.indexOf的用法及实例
.indexOf()用来判断在一个字符串里是否含有另一个字符串。
如果含有,那么返回值表示的是含有字符串的位置,即从第几个字母开始为匹配的字符串;
如果没有,那么返回值为-1。
实例一:
let text = "Hello world, welcome to the universe.";
let result = text.indexOf("welcome");
返回值为13。
实例二:
let text = "Hello world, welcome to the universe.";
text.indexOf("a");
返回值为-1。