Akshay
Akshay

Reputation: 391

Filter JSON data with jquery

Hi I have a JSON format of the following -

{  
   "0":{  
      "name":"example",
      "age":"21"
   },
   "1":{
      "name":"example2",
      "age":"22"
   }
}

I want to convert it to the following format with jQuery -

   {  
      "name":"example",
      "age":"21"
   },
   {
      "name":"example2",
      "age":"22"
   }

removing numbering from keys. Please suggest.

Upvotes: 0

Views: 88

Answers (2)

Mr. Wu
Mr. Wu

Reputation: 33

var json = JSON.parse("your json");
var keys = Object.getOwnPropertyNames(b);
for(var i=o;i<keys.length;i++){
  console.log(b[keys[i]]);
}

Here you go "numbering" removed is over btn Storing parsed objects should be stored in collections, and keys are required to exist in objects. please refer to

Upvotes: 0

vahdet
vahdet

Reputation: 6729

You really do not need JQuery for this. You can use Object.values() function to get an array of values for each property in the object:

const input = {  
   "0":{  
      "name":"example",
      "age":"21"
   },
   "1":{
      "name":"example2",
      "age":"22"
   }
}

const result = Object.values(input)

console.log(result)

I assume your desired result is an array.

Upvotes: 5

Related Questions