javascript - Count times a value is repeated in data fetched using REST call -


i'm fetching data sharepoint using rest, , works fine, except count times same item appears.

this jquery:

 var url = "https:xxxxxxxx/_vti_bin/listdata.svc/rmsd_tasks?$orderby=typeofissuevalue asc,statusvalue desc&$filter=statusvalue ne 'completed'&groupby=typeofissuevalue/statusvalue"; var lastissue = '';  $.getjson(url, function (data) {  $('#totalcounter').text(data.d.results.length);   (var = 0; < data.d.results.length; i++) {      var datereceived = data.d.results[i].datereceived;     datereceived = new date(parseint(datereceived.replace("/date(", "").replace(")/", ""), 10)).tolocalestring('en-us', {         year: 'numeric',         month: 'numeric',         day: '2-digit'     });     var issue = data.d.results[i].typeofissuevalue;         console.log(data.d.results[i].typeofissuevalue);      if (issue != lastissue) {          lastissue = issue;          $('#mydatalist').append('<a href="#" class="list-group-item">' + issue + '<span class="badge">' + issue.length + '</span></a>');      }  }   }); 

i need count how many time specific typeofissuevalue appears. when see console shows add me info:

enter image description here

i added issue.length in badge want insert number sake of having there, know won't show want. thanks!

you first map typeofissuevalue values new array , count each occurence based on this answer.

the code :

var = data.d.results.map(function(issue) {     return issue.typeofissuevalue }); result = {}; (i = 0; < a.length; ++i) {     if (!result[a[i]])         result[a[i]] = 0;     ++result[a[i]]; } 

the result object property being type of issue , value being count of each.

let me know if makes sense.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -