Object from pairs

JavaScript, Object, Array · Oct 21, 2020

Creates an object from the given key-value pairs.

const objectFromPairs = arr =>
  arr.reduce((a, [key, val]) => ((a[key] = val), a), {});
objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2}

More like this

  • Object to pairs

    Creates an array of key-value pair arrays from an object or other iterable.

    JavaScript, Object · Oct 22, 2020

  • Object to pairs

    Creates an array of key-value pair arrays from an object.

    JavaScript, Object · Sep 15, 2020

  • Object to entries

    Creates an array of key-value pair arrays from an object.

    JavaScript, Object · Sep 15, 2020