0

The two metohds, indexOf() , search()are equal ? In java script !!

this methods return same value, accept same argument , then why two different method is use ??

24th Jun 2017, 2:28 AM
deepanshu samdani
deepanshu samdani - avatar
2 Answers
+ 4
indexOf() is an Array object based method, searching in a string as an arrat like object (array of char), while search() is effectively regular expression based... They are not stricly the same, even if they are equivalent on some context ^^
24th Jun 2017, 4:41 AM
visph
visph - avatar
+ 3
"The search value can be string or a regular expression." So I suppose search() is designed for regular expressions, while indexOf is not. Quote from: https://www.w3schools.com/jsref/jsref_search.asp
24th Jun 2017, 2:53 AM
Rrestoring faith
Rrestoring faith - avatar