30 seconds of code

  Back to Home

objectFromPairs

objectarraybeginner

Creates an object from the given key-value pairs.

Use Array.prototype.reduce() to create and combine key-value pairs.

const objectFromPairs = arr => arr.reduce((a, [key, val]) => ((a[key] = val), a), {});