I am trying to add an extra key in a JSON array by searching any key value.
Example JSON:-
[
{
"$id": "2025",
"ID": 41,
"Name": "APPLE"
},
{
"$id": "2026",
"ID": 45,
"Name": "MANGO"
},
{
"$id": "2027",
"ID": 48,
"Name": "GUAVA"
}
]
Suppose I have to add a new key pair example "Price": 50 after "Name": "MANGO" or by finding ID ID": 45. So my expected new JSON will be :-
[
{
"$id": "2025",
"ID": 41,
"Name": "APPLE"
},
{
"$id": "2026",
"ID": 45,
"Name": "MANGO",
"Price": 50
},
{
"$id": "2027",
"ID": 48,
"Name": "GUAVA"
}
]
It must add on the object related to matched search key.
So, I am not able to find out any function related to the issue.
array.map(function(x) { return x.ID; }).indexOf(45)