loop through 'distinct' values and ignore duplicates - javascript -
i'm rewriting question explain better,
i have list of objects shown in image.
these have property statuscode: 62467 journey property goes like: 0,1,2,3,3,4,4,4,4
i want loop through these objects , homecoming first of duplicated objects same journey number.
so want homecoming bold objects: 0,1,2,3,3,4,4,4,4
$.each(points, function (index, point) { (i = 0; < journeynumber.length; i++) { if (point.k.journey === journeynumber[i] && point.k.statuscode === '62467') { console.log(point); latlngs.push(point.j.aa.k); latlngs.push(point.j.aa.b); } } });
the screenshot log of console.log(point), ideally loop within returns first object of same journey number.
hope makes sense , give thanks time.
you can track numbers have been dealt with, and, on finding duplicates of them, skip them.
var already_seen = []; //container logging unique values $.each(points, function(index, point) { if (already_seen.indexof(point) !== -1) return; //if in container, skip already_seen.push(point); //log unseen values in container (i = 0; < journeynumber.length; i++) { if (journey === journeynumber[i] && statuscode === '62467') { latlngs.push(lat); latlngs.push(lng); console.log(journey) } } });
javascript loops for-loop
No comments:
Post a Comment