Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 347 Bytes

objectFromPairs.md

File metadata and controls

16 lines (12 loc) · 347 Bytes
title tags
objectFromPairs
object,array,beginner

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), {});
objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2}