skip to Main Content

This is my json data and I want to remove the outer array.

   [ 
       [ 
          { 
             "name":"name",
             "zip_code":"50700",
             "state":"state",
             "country":"country"
          }
       ]
    ]

I want like that

  [ 
      { 
         "name":"name",
         "zip_code":"50700",
         "state":"state",
         "country":"country"
      }
   ]

2

Answers


  1. You can simply get the first element of the array, so [0] of the array.

    
    // If you have your array
    const myArray =   [ 
           [ 
              { 
                 "name":"name",
                 "zip_code":"50700",
                 "state":"state",
                 "country":"country"
              }
           ]
        ]
    
    // This will  give you what you want.
    myArray[0]
    
    
    Login or Signup to reply.
  2. If you can’t change the JSON to not return a nested array, just target the 0th index of the array. Code example:

    var jsonData = [
        [
            {
                Name: 'John Doe'
            }
        ]
    ]
    
    var strippedJsonData = jsonData[0];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search