Recently, I encountered a JSON object with the following structure:
var js = '{
"person" : {
"firstname" : "Steve",
"lastname" : "Smith",
"other": [
{
"age" : "32",
"deceased" : false
},
{
"age" : "14",
"deceased" : false
},
{
"age" : "421",
"deceased" : false
}
]
}
}'
I was able to delete all elements within the "other" array using this code snippet:
var j = JSON.parse(js)
delete j[person.other]
However, my goal is to remove only the node where age equals 14.
The desired outcome would be as follows:
{
"person" : {
"firstname" : "Steve",
"lastname" : "Smith",
"other": [
{
"age" : "32",
"deceased" : false
},
{
"age" : "421",
"deceased" : false
}
]
}
}
In my research, I found that the delete operator (found here) does not offer a conditional statement which could accomplish this task.
Please excuse me if this question seems basic. As a beginner in programming, I am eager to learn.
Thank you for your help.