Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
Chrome 89
Windows
Desktop
3 years ago
Test name Executions per second
For 185876.8 Ops/sec
Map, Filter 137712.6 Ops/sec
Script Preparation code:
AخA
 
var arr = [];
for (var i = 0; i < 1000; i++) {
    arr[i] = {
        id: i
    };
}
Tests:
  • For

    x
     
    const getListOfPropertyValues = (objectsArray, propertyName) => {
      let mappedList = [];
      for (const object of objectsArray || []) {
        if (propertyName in object) mappedList.push(object[propertyName]);
      }
      return mappedList;
    };
    getListOfPropertyValues(arr, 'id');
  • Map, Filter

     
    const getListOfPropertyValues = (array = [], prop) => array.map(item => item[prop]).filter(item => item);
    getListOfPropertyValues(arr, 'id');