Remove Duplicate Items From Multidimensional Array Using Javascript, jQuery, & underscore.js -
i have web page uses jquery fetch data json file contains location name, latitude, , longitude. push retrieved data array.
var weathersites = []; function weather() { $.getjson('json/locs.json', function(data) { $.each(data.locations, function() { var locationlatitude = this.latitude; var locationlongitude = this.longitude; var locationname = this.location; // -- if latitude , longitude 0,0 skip next iteration -- if (locationtlatitude == +0 || locationlatitude == -0 && locationlongitude == +0 || locationlongitude == -0) { return true; } // populate array site name, latitude, , longitude weathersites.push({name: locationname, latitude: locationlatitude, longitude: locationlongitude}); }); }); }; the code retrieves data , populates array required. however, there number of locationname items same, though locationlatitude and/or locationlongitude different. need remove array elements locationnames same, regardless of latitude or longitude.
i have tried using number of methods seen here have had no luck. example:
function removedupes() { var uniques = _.map(_.groupby(weathersites,function(doc){ return doc.id; }),function(grouped){ return grouped[0]; }); this example requires underscore.js. did not work me. new programming , gis in general. appreciate answer contains full code necessary , logic behind happening. helpful me , of course me learn.
thank help.
the open source project http://www.jinqjs.com can it. here github link: github
var results = jinqjs() .from(data1) .groupby('locationname') .max('locationlatitude', 'locationlongitude') .select(); let me know if need working examples.
Comments
Post a Comment