Answers for "array of obj to obj with reduce"

0

array of obj to obj with reduce

const convertArrayToObject = (array, key) => {
  const initialValue = {};
  return array.reduce((obj, item) => {
    return {
      ...obj,
      [item[key]]: item,
    };
  }, initialValue);
};
Posted by: Guest on August-26-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language