I have nested object like
{
"root": {
"company": [{
"id": "Google",
"contact": [{
"field": "name",
"value": "Larry Page"
}, {
"field": "flag",
"value": ""
}, {
"field": "initial",
"value": "LP"
}
]
}, {
"id": "Snap",
"contact": [{
"field": "name",
"value": "Evan Spiegel"
}, {
"field": "flag",
"value": "true"
}, {
"field": "initial",
"value": "ES"
}
]
}, {
"id": "Airbnb",
"contact": [{
"field": "name",
"value": "Brian Chesky"
}, {
"field": "flag",
"value": ""
}, {
"field": "initial",
"value": "BC"
}
]
}
]
}
}
And i need to create 2 separate lists based on the flag values - one for flag = ""
and another for flag = true
.
Expected results are the 2 lists:
var flagisTrue = {ES}
var flagisEmpty = [{"name":"Larry Page", "initial": "LP"}, {"name":"Brian Chesky", "initial": "BC"}]
where flagisTrue only contains the initial while flagisEmpty contains the name as well as the initial.
How do I work this structure in JavaScript?