Horje
js create object from array Code Example
js array into object
const names = ['Alex', 'Bob', 'Johny', 'Atta'];

// convert array to th object
const obj = Object.assign({}, names);

// print object
console.log(obj);

// {0: "Alex", 1: "Bob", 2: "Johny", 3: "Atta"}
js create object from array
[
  { id: 10, color: "red" },
  { id: 20, color: "blue" },
  { id: 30, color: "green" }
].reduce((acc, cur) => ({ ...acc, [cur.color]: cur.id }), {})

//output: 
{red: 10, blue: 20, green: 30}
js create object from array
 const obj = {};

 for (const key of yourArray) {
      obj[key] = whatever;
 }
return an object from an array javascript
myArray.find(item => item.isAstronaut)
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;
};




Javascript

Related
Encode URL in JavaScript? Code Example Encode URL in JavaScript? Code Example
cypress click link contains text Code Example cypress click link contains text Code Example
Axios FormData / not JSON Code Example Axios FormData / not JSON Code Example
bootstrap 4 navbar-collapse not working angular Code Example bootstrap 4 navbar-collapse not working angular Code Example
jquery ajax responseText Code Example jquery ajax responseText Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7