Saturday, November 22, 2014

.contains is undefined in JAVASCRIPT

String.contains(String) returns undefined in JS in most browsers except Mozilla firefox. We can replace above function with String.indexOf(String).

"Mycars".contains("My") returns true
"Mycars".contains("My1") returns false

"Mycars".indexOf("My") returns the index of the first character of 'My' within 'Mycars'
"Mycars".contains("My1") returns  -1

No comments:

Post a Comment