如果包含单词,则jquery从数组中删除值

时间:2013-11-12 12:40:49

标签: javascript jquery regex google-maps-api-3

我正在使用google maps 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. 
})

3 个答案:

答案 0 :(得分:1)

只需使用jQuery grep()方法。

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

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

答案 1 :(得分:0)

尝试这样的事情:

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

答案 2 :(得分:0)

结果就是你想要的例子。

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