-3

I have a json like this:

var myjson = [
{
    "id": "1"
},
{
    "id": "2"
},
{
    "id": "3"
},
{
    "id": "4"
},
{
    "id": "5"
}
];

I want the incoming id removed from myjson when app.delete() is triggered.

Forexample incoming id = 3. Then myjson's new look:

var myjson = [
    {
        "id": "1"
    },
    {
        "id": "2"
    },
    {
        "id": "4"
    },
    {
        "id": "5"
    }
    ];
BurakBey
  • 33
  • 3
  • What have you tried so far? Maybe [How can I remove a specific item from an array?](https://stackoverflow.com/questions/5767325/how-can-i-remove-a-specific-item-from-an-array) helps. – pzaenger Apr 24 '20 at 14:46

1 Answers1

0

You can use Array.prototype.filter() to do this like the code below:

const removeItem = (id) => myjson.filter(item => item !== id);

Zeyad Etman
  • 1,374
  • 3
  • 18
  • 31