Filter Data In A Json File
I'm currently developing a small application using a JSON file. I have a problem with my data. I must filter my data. For example, I want all the data for a certain User Id but I d
Solution 1:
You can use Array#filter()
The following code is in ES6
const data =[{"ConsoPhot_Id":"7924","idLotImport":166,"Date_Id":20160601,"Orga_Id":"86094","NbTache":35,"NbCopie":143,"NbCopieBW":56,"NbCopieCouleur":87,"MtTotal":3.53},{"ConsoPhot_Id":"7925","idLotImport":166,"Date_Id":20160601,"Orga_Id":"86537","NbTache":291,"NbCopie":969,"NbCopieBW":622,"NbCopieCouleur":347,"MtTotal":15.61},{"ConsoPhot_Id":"7926","idLotImport":166,"Date_Id":20160601,"Orga_Id":"86386","NbTache":7,"NbCopie":32,"NbCopieBW":31,"NbCopieCouleur":1,"MtTotal":0.16},{"ConsoPhot_Id":"7927","idLotImport":166,"Date_Id":20160601,"Orga_Id":"86084","NbTache":2,"NbCopie":3,"NbCopieBW":3,"NbCopieCouleur":0,"MtTotal":0.01},{"ConsoPhot_Id":"7928","idLotImport":166,"Date_Id":20160701,"Orga_Id":"86094","NbTache":33,"NbCopie":68,"NbCopieBW":31,"NbCopieCouleur":37,"MtTotal":1.53}];
const key = "Orga_Id";
const value= "86094";
const result = data.filter(d=>d[key]==value);
console.log(result);
Solution 2:
can do a array filter with native array method Array.filter
varNbCopie = data.filter(function(value) {
return value.Orga_Id == "86094";
});
Solution 3:
you can use jquery for the same like this
**$.each(data, function (i, data) {
if (data.Orga_Id == "86094")
//then the data;
});**
Post a Comment for "Filter Data In A Json File"