Skip to content

Instantly share code, notes, and snippets.

@mrsoftware
Last active May 21, 2019 14:29
Show Gist options
  • Save mrsoftware/eccaf1396e27832b19d6ddbda8d1b4f3 to your computer and use it in GitHub Desktop.
Save mrsoftware/eccaf1396e27832b19d6ddbda8d1b4f3 to your computer and use it in GitHub Desktop.
check if is object in JavaScript
/**
* @param {any} obj The object to inspect.
* @returns {boolean} True if the argument appears to be a plain object.
*/
export default function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}
return Object.getPrototypeOf(obj) === proto
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment