Test name | Executions per second |
---|---|
For | 185876.8 Ops/sec |
Map, Filter | 137712.6 Ops/sec |
var arr = [];
for (var i = 0; i < 1000; i++) {
arr[i] = {
id: i
};
}
const getListOfPropertyValues = (objectsArray, propertyName) => {
let mappedList = [];
for (const object of objectsArray || []) {
if (propertyName in object) mappedList.push(object[propertyName]);
}
return mappedList;
};
getListOfPropertyValues(arr, 'id');
const getListOfPropertyValues = (array = [], prop) => array.map(item => item[prop]).filter(item => item);
getListOfPropertyValues(arr, 'id');