in javascript,Array instance has two methods,
[].indexOf(searchvalue [,start])
and
[].lastIndexOf(searchvalue [,start])
is behaves strange if the “start” param is undefined:
[1,2,3].lastIndexOf(2) // 1
[1,2,3].lastIndexOf(2,undefined) // -1
[1,2,3].indexOf(2,undefined) // 1
this happens in chrome and firefox,so what’s the theory of the indexOf and lastIndexOf treat “undefined” differently
[1,2,3].lastIndexOf(2,undefined)is same as[1,2,3].lastIndexOf(2, 0), so only the first element will be searched.[1,2,3].lastIndexOf(2, 0)will return-1.[1,2,3].lastIndexOf(1, 0)will return0.