简体   繁体   中英

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.

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.

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

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