I am looking to update the value of a specific key in each object within an array as new objects are dynamically added.
Why?
My goal is to further my understanding of array methods and JSON manipulation.
To progress, I posed myself this question: How can I change the value of a key in every object within an array?
Here is the initial data structure:
{
"cars" : [
{
"id": 0,
"color": "blue"
},
{
"id": 3,
"color": "-"
},
{
"id": 0,
"color": {
"id": 0,
"color": "yellow"
}
}
]
}
My objective is to replace the color value in the last subobject with "yellow" dynamically. How can I achieve this?
The desired outcome should look like this:
{
"cars" : [
{
"id": 0,
"color": "blue"
},
{
"id": 3,
"color": "-"
},
{
"id": 0,
"color": "yellow"
}
]
}
Thank you!