Answers for "create object from an array"

6

convert array to object javascript

const convertArrayToObject = (array, key) =>
  array.reduce(
    (obj, item) => ({
      ...obj,
      [item[key]]: item
    }),
    {}
  );
Posted by: Guest on May-05-2020
0

js array to object with keys

const arr = ['a','b','c'];
const res = arr.reduce((a,b)=> (a[b]='',a),{});
console.log(res)
Posted by: Guest on June-02-2020

Code answers related to "create object from an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language