Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array of obj to obj with reduce

const convertArrayToObject = (array, key) => {
  const initialValue = {};
  return array.reduce((obj, item) => {
    return {
      ...obj,
      [item[key]]: item,
    };
  }, initialValue);
};
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #array #obj #obj #reduce
ADD COMMENT
Topic
Name
6+9 =