convert arrays to json objects using js

You can do this with .reduce:

var array = [1, 2, 3, 4]; 

var res = array.reduce((acc,item,index) => {
  acc[`place${index}`] = item;
  return acc;
}, {});
 
console.log(res);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top