Skip to content

Instantly share code, notes, and snippets.

@apolopena
Created January 13, 2019 10:09
Show Gist options
  • Save apolopena/04bf0ec509d8d8348f6133e0ed50047d to your computer and use it in GitHub Desktop.
Save apolopena/04bf0ec509d8d8348f6133e0ed50047d to your computer and use it in GitHub Desktop.
JavaScript: plucking values using Array,prototype.map
var cars = [ {make: "Nissan",
model: "Maxima"},
{make: "Infinity",
model: "G60RS"}
];
function pluck(array, property) {
var results = [];
array.map(function(item){
results.push(item[property]);
});
return results;
}
makes = [];
console.log(pluck(cars, "make"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment