search()
方法搜索特定值的字符串,并返回匹配的位置:
实例
var str = "The full name of China is the People's Republic of China."; var pos = str.search("locate");
两种方法,indexOf()
与 search()
,是相等的。
这两种方法是不相等的。区别在于:
- search() 方法无法设置第二个开始位置参数。
- indexOf() 方法无法设置更强大的搜索值(正则表达式)。
热门文章
-
js charAt()和 charCodeAt()方法的使用(js 查找字符串)
2023-10-09 09:46
-
js lastIndexOf() 方法返回指定文本在字符串中最后一次出现的索引
2023-10-09 09:59
-
js indexOf()查找字符串中的字符串
2023-10-09 09:58