简体   繁体   中英

How we remove full object of array from array of object using JavaScript or lodash?

My JSON looks like this :

     {
      "success": true,
      "data": [
        {
          "user": {
            "firstname": "demo",
            test1": {
              "role": {
                "name": "demo"
              },
              "status": "pending",
              "test2": {
                "telephone": "+demo"
              }
            }
          },
          "authData": [
            {
              "_key": "demo",
              "_id": "demo",
            }
          ]
        }
      ],
      "session": {
        "_key": "demo",
        "uid": "demo",
      }
    }

I want to remove authData array from JSON.

First your JSON is invalid. This is corrected version:

{
          "success": true,
          "data": [
            {
              "user": {
                "firstname": "demo",
                "test1": {
                  "role": {
                    "name": "demo"
                  },
                  "status": "pending",
                  "test2": {
                    "telephone": "+demo"
                  }
                }
              },
              "authData": [
                {
                  "_key": "demo",
                  "_id": "demo"
                }
              ]
            }
          ],
          "session": {
            "_key": "demo",
            "uid": "demo"
          }
        }

Now you can use DELETE operator to delete your key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM