I have the following JSON data:
json = [{
"code3": "ALB",
"asset": 9,
"biodiversity": 4,
"infrastructure": 15
}, {
"code3": "GHN",
"asset": 4,
"biodiversity": 5,
"infrastructure": 5,
}, {
"code3": "TGO",
"asset": 3,
"biodiversity": 6,
"infrastructure": 7
}]
My goal is to filter it down to the following using a for loop:
result = [{
"code3": "ALB",
"asset": 9
}, {
"code3": "GHN",
"asset": 4
}, {
"code3": "TGO",
"asset": 3
}]
I want to know the most efficient way to achieve this. I am aware that I could use
json.forEach(j => del j["infrastructure"] ...
or similar, but I specifically want to filter based on the keys code3, asset
.