find a string within substring jQuery
string contains substring jquery
First OptionThis indexOf() method will return the position of the match, or -1 if it isn’t found.
// returns -1 if doesn't contains // Note that this is case-sensitive if (str.indexOf("Hello") >= 0) { //string contains Hello } // OR // If you want a case-insensitive search, you can write // returns -1 if doesn't contains if (str.toLowerCase().indexOf("hello") >= 0) { //string contains hello }Second Option
//returns false if doesn't contains if (/hello/i.test(str)) { //string contain Hello }
find a string within substring jQuery
Reviewed by Bhaumik Patel
on
7:50 PM
Rating: