469,289 Members | 2,330 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

indexOf is not a function

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.
Aug 11 '05 #1
2 12646
That is (most likely) because indexOf is a method on string objects,
and not on array objects.

Aug 11 '05 #2
Shang Wenbin wrote:
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[i]==val) return i;
}
return -1;
}
myarray = new Array(2, 5, 9);
alert(myarray.getIndex(2))
Mick
Aug 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Glenn M | last post: by
2 posts views Thread by d.schulz81 | last post: by
2 posts views Thread by Bernard Bourée | last post: by
11 posts views Thread by Al | last post: by
25 posts views Thread by Gordon Cowie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.