There are ways to find the string in javascript
Is to use
indexOf ()
To find the string
Such as
var str="Hello Zoearth!" alert(str.indexOf("Zoe")); //is 6 alert(str.indexOf("Hello")); //is 0 alert(str.indexOf("Moon")); //is -1
It should be noted that when the position is zero when found
Direct judgment will become FALSE
So to determine whether the find string
Best to use
var str="Hello Zoearth!" if (str.indexOf("Hello") > -1) { alert(1); } else { alert(2); }
Such judges will be accurate
Thanksgiving!
Message Board
Feel free to leave suggestions and share! Thanksgiving!