Value is object-like

OSCC · JavaScript, Type, Object · Sep 15, 2020

Checks if a value is object-like.

  • Check if the provided value is not null and its typeof is equal to 'object'.
const isObjectLike = val => val !== null && typeof val === 'object';
isObjectLike({}); // true
isObjectLike([1, 2, 3]); // true
isObjectLike(x => x); // false
isObjectLike(null); // false

Recommended snippets

  • Collection is empty

    JavaScript, Type

    Checks if the a value is an empty object/collection, has no enumerable properties or is any type that is not considered a collection.

  • Value is promise-like

    JavaScript, Type

    Checks if an object looks like a Promise.

  • Value is object

    JavaScript, Type

    Checks if the passed value is an object or not.