I have an array:
[ [ \'cardType\', \'iDEBIT\' ],
[ \'txnAmount\', \'17.64\' ],
[ \'txnId\', \'20181\' ],
[ \'txnType\', \'Purchase\' ],
[ \'txnDate\
easiest way to do it where array is of your JSON data :
var obj = {};
array.forEach(function(Data){
obj[Data[0]] = Data[1]
})
In my case, all other solutions didn't work, but this one did:
obj = {...arr}
my arr is in a form: [name: "the name", email: "the@email.com"]
ES5 Version using .reduce()
const object = array.reduce(function(accumulatingObject, [key, value]) {
accumulatingObject[key] = value;
return accumulatingObject;
}, {});