473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

indexOf an array?

42
Hello, i was wondering if its possible to check the my value against an array?
Lets say I have 5 characters i dont want the user to have in the input field so instead of writeing like this:

Expand|Select|Wrap|Line Numbers
  1. my_value.indexOf('first') == -1
  2. my_value.indexOf('second') == -1
  3. my_value.indexOf('3rd') == -1
  4. my_value.indexOf('4th') == -1
  5. my_value.indexOf('5th') == -1 and so on...
  6.  
  7. I would write like this:
  8. var array_value = new Array("first", "second", "3rd", "4th" ,"5th");
  9. value.indexOf(array_value) == -1
I tried that but couldnt get it to work, so is it possible to do this?
Jul 29 '07 #1
2 1556
gits
5,390 Expert Mod 4TB
hi ...

try something like the following:

Expand|Select|Wrap|Line Numbers
  1. var array_value = new Array("first", "second", "3rd", "4th" ,"5th");
  2.  
  3. for (var i = 0; i < array_value.length; i++) {
  4.     if (value.indexOf(array_value[i]) == -1) {
  5.         // do something
  6.     } else {
  7.         // do something other
  8.     }
  9. }
  10.  
kind regards
Jul 30 '07 #2
Gozil
42
Thanks, that will do it
Jul 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Shang Wenbin | last post by:
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 ...
1
by: Herve MAILLARD | last post by:
Hi, Hi have the following array public struct Type_Var { public int ID; public string Mnemonique; public DateTime Date; public float Valeur;
4
by: Reena | last post by:
Hi, code from .aspx page... using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web;
2
by: John Bailo | last post by:
How come String does not have an indexOf method ?
18
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...
11
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 =...
6
by: JP | last post by:
I have a piece of code where a need to look for specific patterns in a string. Because there are over 20 patterns I want to place these in a string array for quick access ...
1
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...
1
by: mad.scientist.jr | last post by:
I am working in C# ASP.NET framework 1.1 and for some reason Regex.Split isn't working as expected. When trying to split a string, Split is returning an array with the entire string in element ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.