Script Preparation code:
x
 
var arr = [];
for (var i = 0; i < 1234; i++) {
    const obj = {};
    obj[`${i}key`] = i;
    arr.push(obj);
}
function shuffle(array) {
    let currentIndex = array.length,
        randomIndex;
    // While there remain elements to shuffle.
    while (currentIndex > 0) {
        // Pick a remaining element.
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex--;
        // And swap it with the current element.
        [array[currentIndex], array[randomIndex]] = [
            array[randomIndex], array[currentIndex]
        ];
    }
    return array;
}
shuffle(arr);
var arr2 = [];
for (var i = 0; i < 12345; i++) {
    const obj = {};
    obj[`${i}key`] = i;
    arr2.push(obj);
}
Tests:
  • map and filter

     
    arr2.map((item, key) => arr[key]).filter(item => item);
  • reduce

     
    arr2.reduce((acc, item, key) => {if(arr[key]){acc.push(item)}return acc;}, [])
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    map and filter
    reduce

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Firefox 121 on Windows
View result in a separate tab
Test name Executions per second
map and filter 8360.3 Ops/sec
reduce 12799.1 Ops/sec