Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert a string array into object using kerys

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