Skip to content

Instantly share code, notes, and snippets.

@jonguenther
Last active September 24, 2020 08:26
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 jonguenther/c52b429f6f4fadcdbc241e8972bab011 to your computer and use it in GitHub Desktop.
Save jonguenther/c52b429f6f4fadcdbc241e8972bab011 to your computer and use it in GitHub Desktop.
Jon's Javascript collection
// get array of unique keys in array of objects
const getUniqueKeys = (ArrayOfObjects) => new Set(ArrayOfObjects.reduce((acc, cur) => [...acc, ...Object.keys(cur)], []));
// conditional properties inside objects
const fooCondition = false;
const conditionalObject = {
someProperty: 'foo',
...(fooCondition && { bar: true }),
anotherProperty: 'bar',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment