Skip to content

Instantly share code, notes, and snippets.

@itmammoth
Last active April 18, 2018 07:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itmammoth/f65388f260b57b0015ee3b13e8a093b5 to your computer and use it in GitHub Desktop.
Save itmammoth/f65388f260b57b0015ee3b13e8a093b5 to your computer and use it in GitHub Desktop.
/**
* Usage:
* var models = [{ attributes: { name: 'Scott' } }, { attributes: { name: 'Tiger' } }];
* deepPluck(models, 'attributes', 'name'); //=> ['Scott', 'Tiger']
*/
var deepPluck = function(array) {
var copiedArray = [].concat(array);
for (var i = 1; i < arguments.length; i++) {
copiedArray = _.pluck(copiedArray, arguments[i]);
}
return copiedArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment