What is the best way to do client-side validation against a moderately sized array

Overview:
I have an array of 20 byte strings that needs to be stored in a web page for use when validating user input. I am expecting 25 to 1000 elements in this array.

Questions:
1. The web client will be a mobile device with limited memory and processor capabilities.
2. I'm only limited to client side validation (a technical limitation for us right now).
3. Security is not an issue - I understand that the user can view the source.
4. I don't want to show the array to the user. I want the user to input a value and then I iterate over the array to see if there is a match. If there is no match, I will display a javascript message box to the user.

Q:
What is the best way to store and repeat this data?

0


source to share


1 answer


Instead of iterating, use an associative array and check for the existence of that element:

var myChunks=[]
myChunks['aabbccdd...'] = true

      



Then you can check if the entered value exists with a simple test. No hinges needed:

if(myChunks[myValue]) {
   //found the value
}
else {
  // did not find value
}

      

+1


source







All Articles