Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

create object from array

// create object from array
const createObjectFromArray = (arr) => {
  let obj = {};
  for (let value of arr) {
    obj[value] = ++obj[value] || 1;
  }
  return obj;
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #object #array
ADD COMMENT
Topic
Name
5+8 =