-2
var projects = [
{
"DisciplineId": "10",
"DisciplineName": "General",
"PhaseId": "103",
},
{
"DisciplineId": "20",
"DisciplineName": "General",
"PhaseId": "102",
},
{
"DisciplineId": "30",
"DisciplineName": "General",
"PhaseId": "102",
},
{
"DisciplineId": "71",
"DisciplineName": "General",
"PhaseId": "102",
},
{
"DisciplineId": "81",
"DisciplineName": "General",
"PhaseId": "102",
},
]

Expected Result:
Less than 70: Answer is 3 (ie., 10,20 and 30 in DisciplineId)
Range 70-80: Answer is 1 (ie., 71 in DisciplineId)
Range > 81: Answer is 1 (ie., 81 in DisciplineId)

Any suggestion to achieve through jquery/javascript or angularjs?

Thanks in advance.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Abdul
  • 90
  • 1
  • 9

1 Answers1

0

One of the simple way using jquery to loop the json array

 var lessThan70Cnt = 0;
 var cnt70To80 = 0;
 var greaterThan80 = 0;

 $.each(data, function(index, item){
   if(parseInt(item.DisciplineId) < 70){
      lessThan70Cnt++;
   }
   else if(parseInt(item.DisciplineId) > 70 && parseInt(item.DisciplineId) < 80){
      cnt70To80++;
   }
   else if(parseInt(item.DisciplineId) > 80){
      greaterThan80++;
   }
 });
Navoneel Talukdar
  • 4,393
  • 5
  • 21
  • 42
  • People still use jQuery? –  Feb 17 '18 at 14:15
  • Thank you Neel, this works. – Abdul Feb 17 '18 at 14:20
  • @doodlemeister - yeah, jQuery is great, but completely overkill here! `data.forEach(function(item) {if(+item.DisciplineId < 70) lessThan70Cnt++; else if(+item.DisciplineId <= 80) cnt70To80++; else greaterThan80++;});` – mplungjan Feb 17 '18 at 14:33
  • @doodlemeister - Jquery/javascript is the basis of all latest client side technologies. – Navoneel Talukdar Feb 17 '18 at 17:12
  • @Neel = JS, sure. jQuery, not even close. It's the basis of nothing except the codebase written by devs who still use it for whatever reason. –  Feb 17 '18 at 18:58