471,853 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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 12813
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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.