I would like to check if a string contains another, as if it were a String.contains()
method but apparently there is no method that does this.
Does anyone know of a similar method that does the same thing?
I would like to check if a string contains another, as if it were a String.contains()
method but apparently there is no method that does this.
Does anyone know of a similar method that does the same thing?
var s = "foo";
alert(s.indexOf("oo") != -1);
The indexOf returns the position of a string in another string or -1 if it does not find.
Using a regex it is possible to know if certain text is contained in another, using method match()
. Your regex should be delimited by //
var str = 'algum texto';
if(str.match(/texto/)){
alert('string encontrada');
}