【问题标题】:How to make a match in an array with links and get the id of the array and the value?如何在带有链接的数组中进行匹配并获取数组的 id 和值?
【发布时间】:2019-06-08 20:33:22
【问题描述】:

我有一个像这样 (www.google.com/3ijadk382932) 的数组中来自不同服务器的链接列表,我需要进行搜索,包括 www.google.com/xxxxxxxxx,而在栏后也没有什么字符,并在数组中获取她的位置他们的 ani表单在javascript中做到这一点? 谢谢

let links = ["https://hil.to/744I35354M0"
    ,"https://filerio.in/nr435345oy8veq"
    ,"https://mirrorace.com/m/143538h"
    ,"https://download.jheberg.net/9pv2rewt80f4"
    ,"https://www.indishare.me/ys7dwhretewldm5"
    ,"https://www85.zippyshare.com/v/lOtryrx7"
    ,"https://www.sendspace.com/file/8345370j8"
    ,"https://1fichier.com/?rpc2lrandomltgwmx"];

我需要匹配filerio链接和她在数组中的位置

类似 Filerio = {filerio:link,array:[1]}

【问题讨论】:

  • 这是静态列表吗?任何值都会改变吗?
  • 使用正则表达式或split从搜索字符串中获取域名。然后循环遍历数组,对每个元素执行相同的操作,并将其与从搜索字符串中获得的域进行比较。

标签: javascript arrays pattern-matching


【解决方案1】:
var url ="https://filerio.in/"
   var filteredLink = [];
   links.forEach(function(link){ link.indexOf(url) >= 0 
            ? filteredLink.push({"link" : link, position: 
             link.indexOf(url) }) : jQuery.noop()})

   console.log(filteredLink)

【讨论】:

  • 它可以匹配但它没有给出 id 但是,由于你的同意,我已经解决了代码:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-15
  • 2020-02-02
  • 1970-01-01
  • 2021-03-18
  • 1970-01-01
相关资源
最近更新 更多