I am trying to forEach the values in json and push the desired values to the array by using the map function inside.
[
{
"detail": {
"id": 89,
"content": "123",
"type": "one",
"company": "minsu",
"certificationNum": "minsu"
},
"ingredientList": [
{
"id": 161,
"content": "32523523",
"functionalList": [
{
"id": 129,
"valueUnit": "mg"
}
]
},
{
"id": 162,
"content": "162",
"functionalList": [
{
"id": 130,
"valueUnit": "cm"
}
]
}
]
},
{
"detail": {
"id": 91,
"content": "332",
"type": "two",
"company": "sss",
"certificationNum": "1123-522"
},
"ingredientList": [
{
"id": 164,
"content": "hi",
"functionalList": [
{
"id": 132,
"valueUnit": "kg"
},
{
"id": 133,
"valueUnit": "g"
}
]
},
{
"id": 165,
"content": "succes",
"functionalList": [
{
"id": 134,
"valueUnit": "fie"
},
{
"id": 135,
"valueUnit": "fy"
}
]
}
]
}
]
It's a simple json,
I want to push the json data values to an array and put them as these values.
[
{
"content": "123",
"type": "one",
"certificationNum": "minsu",
"functionalList": {
{
"id": 129,
"valueUnit": "mg"
},
{
"id": 130,
"valueUnit": "cm"
}
}
},
{
"content": "332",
"type": "two",
"certificationNum": "1123-522",
"functionalList": {
{
"id": 132,
"valueUnit": "kg"
},
{
"id": 133,
"valueUnit": "g"
},
{
"id": 134,
"valueUnit": "fie"
},
{
"id": 135,
"valueUnit": "fy"
}
}
}
]
let SeedDetailArray = new Array();
SeedValue.forEach(function(id: any) {
Object.keys(id).forEach(function(props) {
SeedDetailArray.push({
content: id[props]["content"],
type: id[props]["type"],
certificationNum: id[props]["certificationNum"],
functionalList: id[props]["functionalList"],
});
});
})
console.log(SeedValue);
[
{
"content": "123",
"type": "one",
"certificationNum": "minsu",
},
{
"content": "332",
"type": "two",
"certificationNum": "1123-522",
}
]
I put Seed Value json in Seed Detail Array with detail forEach statement, but I don't know how to put the value in functionList.
How do I create json like this?
[
{
"content": "123",
"type": "one",
"certificationNum": "minsu",
"functionalList": {
{
"id": 129,
"valueUnit": "mg"
},
{
"id": 130,
"valueUnit": "cm"
}
}
},
{
"content": "332",
"type": "two",
"certificationNum": "1123-522",
"functionalList": {
{
"id": 132,
"valueUnit": "kg"
},
{
"id": 133,
"valueUnit": "g"
},
{
"id": 134,
"valueUnit": "fie"
},
{
"id": 135,
"valueUnit": "fy"
}
}
}
]