Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript、jQuery和&;从多维数组中删除重复项;下划线.js_Javascript_Jquery_Arrays_Multidimensional Array_Underscore.js - Fatal编程技术网

使用Javascript、jQuery和&;从多维数组中删除重复项;下划线.js

使用Javascript、jQuery和&;从多维数组中删除重复项;下划线.js,javascript,jquery,arrays,multidimensional-array,underscore.js,Javascript,Jquery,Arrays,Multidimensional Array,Underscore.js,我有一个网页,它使用jQuery从包含位置名、纬度和经度的JSON文件中获取数据。然后,我将检索到的数据推送到一个数组中 var weatherSites = []; function weather() { $.getJSON('json/LOCS.json', function(data) { $.each(data.locations, function() { var locationLatitude = this.latitude;

我有一个网页,它使用jQuery从包含位置名、纬度和经度的JSON文件中获取数据。然后,我将检索到的数据推送到一个数组中

 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 the latitude and longitude are 0,0 then skip to the next iteration --
            if (locationtLatitude == +0 || locationLatitude == -0 && locationLongitude == +0 || locationLongitude == -0) {
                return true;
            }

       // Populate array with site name, latitude, and longitude       
       weatherSites.push({name: locationName, latitude: locationLatitude, longitude: locationLongitude});

    });
  });

  }; 
代码检索数据并根据需要填充数组。但是,尽管
locationLatitude
和/或
locationLongitude
不同,仍有许多
locationName
项目相同。我需要从数组元素中删除
locationName
s相同的元素,而不考虑纬度或经度

我尝试过使用这里看到的许多方法,但没有成功。例如:

function removeDupes() {
        var uniques = _.map(_.groupBy(weatherSites,function(doc){
          return doc.id;
        }),function(grouped){
          return grouped[0];
        });
此示例需要下划线.js。这对我不起作用。我是编程和地理信息系统的新手。我希望你能给出一个完整的答案,其中包含必要的完整代码,并希望包含正在发生的事情背后的逻辑。这对我很有帮助,当然也会帮助我学习

谢谢您的帮助。

开源项目可以很容易地做到这一点。 以下是GitHub链接:

如果您需要任何工作示例,请告诉我。

这将非常有用:
var results = jinqJs()
                  .from(data1)
                  .groupBy('locationName')
                  .max('locationLatitude', 'locationLongitude')
                  .select();