Last active
May 21, 2019 14:29
-
-
Save mrsoftware/eccaf1396e27832b19d6ddbda8d1b4f3 to your computer and use it in GitHub Desktop.
check if is object in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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