indexOf is not a function

S

Shang Wenbin

Hi,
I use the following snip:

myarray = new Array(2, 5, 9);
var index = myarray.indexOf(2);

but it is not workable, the debugger says array.indexOf is not a
function.I use mozilla 1.7.10

Any suggestion?

Thank you.
 
X

Xandax

That is (most likely) because indexOf is a method on string objects,
and not on array objects.
 
M

Mick White

Shang said:
Hi,
I use the following snip:

myarray = new Array(2, 5, 9);
var index = myarray.indexOf(2);

but it is not workable, the debugger says array.indexOf is not a
function.I use mozilla 1.7.10

Any suggestion?


Array.prototype.getIndex=function(val){
for(var i=0;i<this.length;i++){
if(this==val) return i;
}
return -1;
}
myarray = new Array(2, 5, 9);
alert(myarray.getIndex(2))
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top