Last active
January 6, 2022 04:47
-
-
Save daveteu/1a64e5f1e3c25d871f9d6b00061e664a to your computer and use it in GitHub Desktop.
Find undefine keys in plain object
This file contains hidden or 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 {object} obj plain object with { key: value } | |
* @param {array} keysToCheck List of keys to check for undefined values e.g. ['a','b','c'] | |
* @example | |
* | |
* const obj = { a: undefined, b: 1, c: 2, d: undefined } | |
* | |
* console.log(keysUndefined(obj)) | |
* returns ['a','d' ] | |
**/ | |
function keysUndefined( obj ) { | |
return Object.keys(obj).filter(x => obj[x] === undefined) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment