开发者

Use of indexOf() Method in JavaScript

var araj=["1","2"];  
var idx=Array.IndexOf(araj,"1");
开发者_运维百科

Doesn't work as expected. Why, and what's next?

EDIT: it is javascript in asp.net (so the friend who won't open account here says)


indexOf has a lowercase i


Javascript is case sensitive language. IndexOf should be indexOf:

var araj=["1","2"];  
var idx=Array.indexOf(araj,"1");

Result:

0

More Info:

http://www.tutorialspoint.com/javascript/array_indexof.htm


Change IndexOf to indexOf.

Javascript is case-sensitive.


Although equivalent, I prefer this method.

var araj = ['1', '2'];
var idx = araj.indexOf('1');
alert(idx);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜