indexOf use in JavaScript

indexOf use in JavaScript

1 Overview

indexOf case-sensitive, which should be capitalized O

2, for purposes of the string

indexOf returns the position of the first occurrence of the string, or -1 if no

1 var str = "hello world";
2 alert(str.indexOf("o"))//显示4
3 alert(str.indexOf("i"))//显示-1

3, for an array of purposes

indexOf Returns the index values ​​in the array a first time, if no -1

1 var arr=["1","2"]
2 alert(result.indexOf("1"));//显示0
3 alert(result.indexOf("0"));//显示-1

Guess you like

Origin www.cnblogs.com/TMesh/p/11832816.html