javascript - How to get only numerical key value pair from json -


i have json data this

{    "info":[       {          "name":"noob here",          "major":"language",          "sex":"male",          "english":"15",          "japanese":"5",          "calculus":"0",          "geometry":"20"       },       {          "name":"noob here",          "major":"calculus",          "sex":"female",          "english":"0.5",          "japanese":"40",          "calculus":"20",          "geometry":"05"       }    ] } 

i need key value pair value numerical data.

expected output

{ "english":"15", "japanese":"5", "calculus":"0",  "geometry":"20" }, {  "english":"0.5", "japanese":"40", "calculus":"20", "geometry":"05" } 

is there plugins or should write long jquery code using regex?.

used jquery isnumeric find if numeric or not.. playing objects , array..you need 2 loops objects...

here go..

var finalobj={};  //this final output object var info = [];  //array push finalobj $.each(data.info,function(i,v){   var object={};   $.each(v,function(i1,val1){     if($.isnumeric(val1)){          object[i1]=val1     }   });   info.push(object); }); finalobj['info']=info; console.log(finalobj); 

fiddle here


Comments