How to convert an array of objects to object with key value pairs

You could use Object.assign and a spread syntax ... for creating a single object with the given array with objects.

var array = [{ name1: "value1" }, { name2: "value2" }],
    object = Object.assign({}, ...array);
    
console.log(object);

Leave a Comment