JSFiddle - React, Tailwind, and code Playground
JavaScript
function pluck(objects, fieldName) {
"use strict";
var arrProps = [];
objects.forEach(function(object, i, objects) {
if (object.hasOwnProperty(fieldName)) {
arrProps.push(object[fieldName]);
}
});
return arrProps;
}
var characters = [
{ 'name': 'barney', 'age': 36 },
{ 'name': 'fred', 'age': 40 }
];
console.log(pluck(characters, 'name')); // ['barney', 'fred']