Skip to content

Instantly share code, notes, and snippets.

@nadavspi
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save nadavspi/20c1861d9efa9f55eb50 to your computer and use it in GitHub Desktop.

Select an option

Save nadavspi/20c1861d9efa9f55eb50 to your computer and use it in GitHub Desktop.
var data = [
{
name: 'Nadav',
school: 'Weber',
interest: 'Jazz'
},
{
name: 'Noy',
school: 'Epstein'
},
{
name: 'Noa',
school: 'Something'
},
];
var combineKeys = function(data) {
return data.map(obj => Object.keys(obj))
.reduce((prev, current) =>
prev.concat(current.filter((key) =>
prev.indexOf(key) < 0))
);
};
console.log(combineKeys(data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment