I am trying to convert Objects
in an Array
to one single Object
in javascript. Here are objects in an array and logic to convert it to one single object.
var arrObj=[{"Plain bold italic text": "2"},{29: "1"},{24: "2"},{21: "2"},{26: "2"},{27: "2"}];
var obj={};
arrObj.forEach((element, index) => {
obj[Object.keys(element)[0]] = parseInt(Object.values(element).toString());
});
console.log(obj);
string
as well as numbers
as keys, but I want to maintain the same order for keys. My logic sorts keys which I don't desire. Expected output:
{"Plain bold italic text": 2, "29": 1,"24": 2,"21": 2,"26": 2,"27": 2}