To check a string exists in other string in JavaScript, we can use indexOf function, if exists this function return 》=0 value,otherwise it will return -1.
For example:
if(str.indexOf(substr)>=0){
// exist
} else{
// not exist
}
To check a string exists in other string in JavaScript, we can use indexOf function, if exists this function return 》=0 value,otherwise it will return -1.
For example:
if(str.indexOf(substr)>=0){
// exist
} else{
// not exist
}
If you are studying javascript, you may want to know have to run it in html, you can do like this.
You can create a html file by dreaweaver, TxtEdito or editplus, which named ‘test.html’, then open it.