473,543 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12951
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=funct ion(val){
for(var i=0;i<this.leng th;i++){
if(this[i]==val) return i;
}
return -1;
}
myarray = new Array(2, 5, 9);
alert(myarray.g etIndex(2))
Mick
Aug 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12524
by: Glenn M | last post by:
how can i use the .indexof function to check if there is a quote in the string. i can't seem to find the correct syntax for do this without an error occuring
2
4552
by: d.schulz81 | last post by:
i am getting the error "indexOf is not a function" when calling URi.indexOf('?') the code: function removeFromURL(URi, parameter) { var regexp, path, params, qStart = URi.indexOf('?') + 1; if (qStart == 0 || qStart == URi.length-1) return URi;
5
5416
by: majm | last post by:
I'm trying to implement strongly typed lists in the 2.0 framework. I'm using VS2005 beta 2. So far, System.Collections.Generic.List appears to be the ideal solution. However, the generic.List.IndexOf function doesn't appear to be invoking the contained class' CompareTo method. My understanding is that it should. The contained class...
12
6709
by: Rubbrecht Philippe | last post by:
Hi there, According to documentation I read the ArrayList.IndexOf method uses the Object.Equals method to loop through the items in its list and locate the first index of an item that returns True. Therefore, overriding the Equals method in the class definition of the items I put in the ArrayList should make the IndexOf method use my...
2
3297
by: Bernard Bourée | last post by:
I have a class named "Variable" with 2 properties "Name" and "Value" and the following class to handle a collection of Variable: Public Class ColVariables Inherits CollectionBase Default Public Property Item(ByVal index As Integer) As Variable Get Return CType(List(index), Variable) End Get Set(ByVal Value As Variable)
5
1876
by: aaapaul | last post by:
Hello ! I have some values stored in a xml-file. When starting my application, I read this file and store the values in a collection object. My problem is the error-handling, if the fieldname does not exist. I dont want to use try and catch. The indexof-function to check would be better, but it is not available.
18
4709
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
11
12815
by: Al | last post by:
This statement returns a -1, indicating "not found": Find1 = Array.IndexOf(FilesArray, "sa001") But IndexOf on a specific item in that array returns a value of 26: Find1 = FilesArray(2).IndexOf("sa001") This shows the value "sa001" is found in FilesArray. Any suggestions why Array.IndexOf does not return a number (index of item that has...
25
2576
by: Gordon Cowie | last post by:
Wouldn't it make sense if IndexOf just threw a character not found exception instead of -1? If -1 is what you were expecting there should be a function ContainsChar that returns bool. Thoughts?
1
8357
Atli
by: Atli | last post by:
The following small HowTo is a compilation of an original problem in getting some cookie-values through different methods of string-handling. The original Problem was posted as follows: As you can see, there could have been a problem with the split-method. The following short article handles ways around this possible problem, that we...
0
7412
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7697
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5892
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3395
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3395
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
648
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.