I have an objects that contains arrays with following structure:
var obj = {
"feature1" : ["val1","val2"],
"feature2" : ["val3"]
}
Now I want to split the values that are present inside of this each array and form a new array of objects that should like :
var result = [
{
"field": "feature1",
"value": "val1",
"type": "add"
},
{
"field": "feature1",
"value": "val2",
"type": "add"
},
{
"field": "feature2",
"value": "val3",
"type": "add"
}
]
Here splitting must happen based on the "field" and it show something that is similar to above.here "type" is an extra field that is hardcoded
Help would be appreciated.