Created
January 13, 2019 10:09
-
-
Save apolopena/04bf0ec509d8d8348f6133e0ed50047d to your computer and use it in GitHub Desktop.
JavaScript: plucking values using Array,prototype.map
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 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