I have an array of objects with a string value in it, with a first array as an header:
var data = [{records : "productId*amount*tax1*tax2*tax3"},
{records : "111*2000*10*12*13"},
{records : "113*3000*10**"}]
I need to convert this array of objects into an individual objects with key-value pairs by using the data[0] as key and rest of the data[x] as its value .
Expected output :
data: [
{
"productId" : "111",
"amount" : '2000",
"tax1" : "10",
"tax2" : "12",
"tax3" : "13"
},
{
"productId" : "113",
"amount" : "3000",
"tax1" : "10",
"tax2" : "0",
"tax3" : "0"
}
]
I can use the split operator to split the strings and get them as an individual array, but can't figure out how to assign it to key value pairs in an array and I'm very new to JS.