Skip to content

Instantly share code, notes, and snippets.

@daveteu
Last active January 6, 2022 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveteu/1a64e5f1e3c25d871f9d6b00061e664a to your computer and use it in GitHub Desktop.
Save daveteu/1a64e5f1e3c25d871f9d6b00061e664a to your computer and use it in GitHub Desktop.
Find undefine keys in plain object
/**
* @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