Object from arrays

Benchmark created on


Setup

const keys = ["a","b","c"];
const data = [1,2,3];

Test runner

Ready to run.

Testing in
TestOps/sec
fromEntries
Object.fromEntries(keys.map((key, index)=> [key, data[index]])); // {a: 1, b: 2, c: 3}
ready
Object.assign
Object.assign.apply({}, keys.map((v, i) => ({[v]: data[i]}) ))
ready
forEach
const result = {};
keys.forEach(function(key, i){result[key] = data[i]});
ready
Reduce
keys.reduce((o, k, i) => ({...o, [k]: data[i]}), {})
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.