How to split javascript object with the same attribute.
Here I have one object
var fields = [
{"Country" : "USA", "key": "Country", Value :"USA"},
{"State" : "SC", "key": "State", Value :"SC"},
{"District" : ["DIST1","DIST2"], "key": "District", Value :["DIST1","DIST2"]}];
I wanted to store this in object like this way
var fields = [
{"Country" : "USA","State" :"SC","District" : "DIST1"},
{"Country" : "USA","State" :"SC","District" : "DIST2"}]
For that what I am trying here is
var myObj = {};
for(var i = 0; i<fields.length; i++){
myObj[fields[i].key] = fields[i].Value
}
and o/p i am getting is
{
Country: "USA"
District:["DIST1","DIST2"]
State: "SC"
}
Any solution for expected o/p. How can split "District here"