Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
forEach vs map by cuteLuna v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
map
1725395.5 Ops/sec
forEach
1679411.2 Ops/sec
for loop
1737686.5 Ops/sec
Tests:
map
const cuteObject = { [1]: [ { name: 'luna', id: 135 } ], [3]: [ { name: 'fat', id: 136 } ] }; const newList = Object.keys(cuteObject).map(key => { const options = cuteObject[key].map(item => ({ label: item.name, name: item.name, id: item.id, })); return { label: key, options: options, }; });
forEach
const cuteObject = { [1]: [ { name: 'luna', id: 135 } ], [3]: [ { name: 'fat', id: 136 } ] }; const newList = []; Object.keys(cuteObject).forEach(key => { const options = []; cuteObject[key].forEach(item => { options.push({ label: item.name, name: item.name, id: item.id, }); }); newList.push({ label: key, options: options, }); });
for loop
const cuteObject = { [1]: [ { name: 'luna', id: 135 } ], [3]: [ { name: 'fat', id: 136 } ] }; const newList = []; const keys = Object.keys(cuteObject); const keysLength = keys.length; for (let i = 0; i < keysLength; i++) { const key = keys[i]; const options = []; const items = cuteObject[key]; const itemsLength = items.length; for (let j = 0; j < itemsLength; j++) { const item = items[j]; options.push({ label: item.name, name: item.name, id: item.id, }); } newList.push({ label: key, options: options, }); }