As the title states, I am trying to return an array containing the value associated with that key for each object, or undefined if that key is not present.
Here is what I have so far:
function pluck(arr, name) {
permittedValues = arr.map(function(value) {
return value.key || undefined;
});
}
console.log(
pluck([
{ name: "Tim" }, { name: "Matt" }, { name: "Elie" }],
'name'
)
);
I am trying to return something like this:
// ["Tim", "Matt", "Elie"]
value[name]would be the array syntaxvalue.keyis the property namedkey, not the property named whatever the value ofkeyis. See e.g. stackoverflow.com/q/4841254/3001761.key. Did you mean to writefunction pluck(arr, key)?