Use indexOf() method of JavaScript string to check if string contains particular given sub string or not.
String.prototype.indexOf
returns the position of the string in the other string. If not found, it will return -1
:var string = "some string", substring = "some"; if(string.indexOf(substring) > -1) { // String contains given substring // do your stuff here }else { // String haven't containg given substing }
Tags:
Javascript
JavaScript - Check if string contains given substring
By yash →
Wednesday, May 11, 2016