javascriptjson

Remove JSON element


I want to remove JSON element or one whole row from JSON.

I have following JSON string:

{
   "result":[
       {
           "FirstName": "Test1",
           "LastName":  "User",
       },
       {
           "FirstName": "user",
           "LastName":  "user",
       },
       {
           "FirstName": "Ropbert",
           "LastName":  "Jones",
       },
       {
           "FirstName": "hitesh",
           "LastName":  "prajapti",
       }
   ]
}

Solution

  • var json = { ... };
    var key = "foo";
    delete json[key]; // Removes json.foo from the dictionary.
    

    You can use splice to remove elements from an array.