I\'m trying to recreate the Underscore pluck function using pure JS. However, I keep getting an array of undefineds being returned, instead of the actual values from the pr
You are so close. You need to change:
newArr.push(arr[i].key);
to:
newArr.push(arr[i][key]);
Consider this:
var obj = { myKey: 'my Value', theKey: 'another value' };
var theKey = 'myKey';
alert(obj.theKey); // another value
alert(obj[theKey]); // my Value
// You can also send in strings here:
alert(obj['theKey']); // another value
Hope you get my point.