0

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

2
  • 1
    json.filter(p => !remObj.includes(p.name)) Commented Jun 27, 2022 at 16:52
  • 2
    Please note that let json means the data is just normal javascript data, not JSON Commented Jun 27, 2022 at 16:54

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.