Recently I was writing logic in JavaScript and I wrote something like this
var str="hello world";
if(str.contains("w"))
//do something
else
//do anotherthing
I thought it was working fine until I ran the page in Chrome. In Chrome I'm getting an error of contains is not a function
.
Although I got rid of this by modifying the logic as
var str="hello world";
if(str.indexOf("w")!=-1)
//do something
else
//do another thing
is contains
not a standard ECMAScript function? I'm able to see contains
through intellisense in Firefox but not in Chrome.
While testing these in different browsers I noticed in the console that
String.subString/indexOf //not showing in chrome but works in Firefox
instead str.substring/indexOf
works in chrome
Aren't these methods are part of standard String
object?