【发布时间】:2016-05-19 08:39:09
【问题描述】:
我浏览了许多帖子(和其他网站),似乎遇到了障碍。我有以下数组:
var data_dictionary = ["youtube.com", "facebook.com", "youtube.com/feed/subscriptions", "twitter.com"]
我正在尝试返回包含 youtube.com* 的所有内容的数据。下面是我函数的相关sn-p:
var result = []
for (var i=0; i<data_dictionary.length; i++) {
if (data_dictionary[i].page == /^youtube.com/) {
result.push (data_dictionary[i].page,data_dictionary[i].share)
}
}
break;
}
return result
问题在于 if 子句 (/^youtube.com/)。我怎样才能收到以下回报:
["youtube.com" , "youtube.com/feed/subscriptions"]
【问题讨论】:
-
与正则表达式比较使用
data_dictionary[i].page.match(/^youtube.com/) -
完美运行!很高兴学习这个(对 JS 很陌生)。
标签: javascript arrays wildcard