I have an object
{
"input":{
"id": "7879",
"inputType": "9876",
"streamName": "870"
},
"transformation":{
"id": "7",
"dependencies": [
"8i"
],
"dropColumns": "hkj",
"processor": "hgf"
},
"output": {
"id": "v",
"saveMode": "uyt",
"dependentIds": [
"h"
],
"outPartition":[
"hg"
]
}
}
Basically every value leaving the key I have to put it in an array. So input, transformation, output values(which are objects) should be placed inside array.
Expected Output:
{
"input": [
{
"id": "7879",
"inputType": "9876",
"streamName": "870"
}
],
"transformation":[
{
"id": "7",
"dependencies": [
"8i"
],
"dropColumns": "hkj",
"processor": "hgf"
}
],
"output":[
{
"id": "v",
"saveMode": "uyt",
"dependentIds": [
"h"
],
"outPartition":[
"hg"
]
}
]
}
I tried iterating using the for in loop but was not able to achieve the expected output how should I place the values(object) inside array
var arr = [];
for(key in obj){
arr.push(Object.assign(obj[key],{name: key}))
}
arr? WhyObject.assign()? Why{name: key}?