Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 从束中删除带有特定单词的url_Javascript_Jquery - Fatal编程技术网

Javascript 从束中删除带有特定单词的url

Javascript 从束中删除带有特定单词的url,javascript,jquery,Javascript,Jquery,我是Jquery的新手。我想删除所有包含g1的url。如何使用Jquery实现这一点 这是代码 var url = "http://www.example.com/"; var links = []; //GET ALL LINKS $html.find('.title h2 a').each(function(i, obj) { var link = app.makeLink(url, $(this).attr('href')); if (link != null) {

我是Jquery的新手。我想删除所有包含g1的url。如何使用Jquery实现这一点

这是代码

var url = "http://www.example.com/";
var links = [];

//GET ALL LINKS
$html.find('.title h2 a').each(function(i, obj) {
    var link = app.makeLink(url, $(this).attr('href'));
    if (link != null) {
        links.push(link);
    }
});
这是结果(在数组中):

www.example.com/g1/a
www.example.com/c1/b
www.example.com/g1/c
www.example.com/c1/d
www.example.com/c1/e
www.example.com/g1/f
www.example.com/g1/g
www.example.com/g1/h
www.example.com/c1/i
www.example.com/g1/j

您可以使用JavaScript函数
String.indexOf
。使用它,您可以搜索字符串中的子字符串。如果子字符串不存在,则返回-1

$html.find('.title h2 a').each(function(i, obj) {
    var link = app.makeLink(url, $(this).attr('href'));
    if (link != null && link.indexOf("g1") == -1) {
        links.push(link);
    }
});

从何处删除URL?这是一个数组吗?请显示一些代码。这些URL在哪里?这些字符串在数组中吗?