[Solved] JavaScript – array, object – How can I streamline this code


You can use .reduce() and Object.entries() methods:

const aa = ['red', 'yellow', 'blue']
const bb = { first: 0, second: 1, third: 2 }

const cc = Object.entries(bb)
                 .reduce((r, [k, i]) => (r[k] = aa[i], r), {});

console.log(cc);

solved JavaScript – array, object – How can I streamline this code