Overview:
I have an array of 20 byte strings that needs to be stored on a web page for use in user entry validation. I anticipate between 25 and 1000 elements in that array.
Considerations:
1. The web client will be a mobile device with reduced memory and processor capability.
2. I am limited to client-side validation only (technical limitation for us right now).
3. Security is not an issue – I understand that the user can view the source.
4. I do not want to show the array to the user. I only want the user to enter a value, and then I iterate over the array to see if there’s a match. If no match, I will issue a javascript message box to the user.
Question:
What is the best way to store and iterate over this data?
Instead of iterating, use an associative array, and test for the existence of that element:
Then you can check for the existance of the entered value by a simple test. No loops required: