Merge keys array and values array into an object in JavaScript

The simplest ES6 one-liner solution using Array reduce:

const keys = ['height', 'width'];
const values = ['12px', '24px'];
const merged = keys.reduce((obj, key, index) => ({ ...obj, [key]: values[index] }), {});

Leave a Comment