Remove element in json

问题描述 投票:-1回答:1

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"
    }
    ];
node.js express
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.