Created
August 22, 2015 02:03
-
-
Save emanuelfeld/c8554567676923dc034b to your computer and use it in GitHub Desktop.
Node.js script for creating an array of all unique keys in an array of Javascript objects.
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
var _ = require('underscore') | |
function allKeys (In, Out) { | |
for (var i = 0; i < In.length; i++) { | |
var fieldArray = Object.keys(In[i]) | |
if (!(Out.some(function (b) { return _.isEqual(fieldArray, b)}))) { | |
Out.push(fieldArray) | |
} | |
} | |
var OutCombined = _.reduce(Out, function(a, b) { return a.concat(b); }, []); | |
var OutUnique = _.uniq(OutCombined) | |
return OutUnique | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment