im trying to remove from my JSON file one object from the array:
let json = [{
"name":"John",
"age":"29"
},
{
"name":"Billy",
"age":"45"
}];
I have an array that has the data to remove from JSON, it only has name in it
let remObj = ['John'];
Is it possible to remove only using name?
Edit:
I have tried Slice, Splice and filter
1 Answer 1
Does this work for you?
let json = [{
"name":"John",
"age":"29"
},
{
"name":"Billy",
"age":"45"
}];
let remObj = ['John'];
const newJson = json.filter(p => !remObj.includes(p.name))
console.log(newJson)
answered Jun 27, 2022 at 16:53
Orkhan Alikhanov
10.2k4 gold badges50 silver badges66 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
json.filter(p => !remObj.includes(p.name))let jsonmeans the data is just normal javascript data, not JSON