Array of key values - Object.entries VS Object.keys
Date tested:
2 years ago
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Test name
Executions per second
Object.entries
128656.1 Ops/sec
Object.keys
51759.2 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } window.parentObj = {}; for (let i = 0; i < 100; i++) { window.parentObj[makeid()] = makeid(); }
Tests:
Object.entries
Object.entries(window.parentObj).map(([id, name]) => { return {id, name} });
Object.keys
Object.keys(window.parentObj).map(id => { const name = window.parentObj[id]; return { id, name }; });
Open this result on MeasureThat.net