j查询从数组中删除值(如果包含单词)

jquery delete value from array if contains a word

本文关键字:如果 包含单 删除 查询 数组      更新时间:2023-09-26

我正在使用谷歌地图API,我想做的是使用jQuery作为过滤器,从其位置数据中删除位置

因此,如果用户单击过滤器英语,那么jQuery将查找不包含英语的条目,然后一旦找到它们,它将删除[ ]及其内容。

var LocationData = [
[-33.911187337771345,18.41437339782715,"<a class=english href=http://lang.beresponsive.net/blog/2013/09/10/hello-world/>Hello world!</a>","http://lang.beresponsive.net/wp-content/uploads/2013/11/Logo.png"],
[-33.95902344617683,18.481578826904297,"<a class=french href=http://lang.beresponsive.net/blog/2012/07/30/cu-vel-suas-interpretaris-no-qui-tantas-2/>Lightbox Image</a>","http://lang.beresponsive.net/wp-content/uploads/2013/11/Logo.png"],
 ]; 

我在想类似的事情

jQuery('.filter-eng').click(function(){
  //not sure what would go here to preform this. 
})

只需使用 jQuery grep() 方法即可。

http://api.jquery.com/jQuery.grep/

var NewLocationData = $.grep(LocationData, function(val) { 
  return val[1].indexOf("english") === -1; 
});

尝试这样的事情:

for (x in LocationData) {
     $.grep(x, function(value) {
           return value.match("class=english") != null;
           },
           true);
}

结果是给定示例所需的结果。

var result = $.grep(LocationData, function(location) {
    return /english/i.test(location[2]);
});