【发布时间】:2013-12-09 22:44:23
【问题描述】:
我需要在数组中找到单词的索引。但是对于以下场景
var str="hello how are you r u fineOr not .Why u r not fine.Please tell wats makes u notfiness".
var splitStr=str.split(" ");
//in splitStr array fineOr is stored at da index of 6.
//in splitStr array notfiness is stored at da index of 18.
var i=splitStr.indexOf("**fine**");
var k=splitStr.lastindexOf("**fine**");
console.log('value i-- '+i); it should log value 6
console.log('value k-- '+k); it should log value 18
我需要如何传递正则表达式来搜索字符串“fine”以获得数组的函数 indexOf?
【问题讨论】:
-
你不能在那里传递正则表达式,因为 indexOf 不是这样工作的。
-
@CBroe 是的,也许值得提出功能请求? tc39.github.io/process-document
标签: javascript regex arrays