b.mic
04-15-2004, 04:24 AM
Hello,
I have a series of words (server-side generated) that counts about 300 items (but likely to grow in time), and I would like to check (client side) whether what the user typed in a certain field matches one of the words in the series.
To do this, I know I can put that series of words in a javascript array, then iterate through the array and test each word for equivalence to the user input.
Or maybe put all the words in one long string and then use regexp.
As for the first option, I'm afraid of the time cost if the series of words gets bigger.
As for the second option, as I don't know the content of the series of words and the user input, I think it could be a bit tricky.
I was wondering if there was a javascript equivalent to the Java "List" object (or, more precisely, "ArrayList", as "List" is an interface), which has a method "contains()" that exactly fits my need. I didn't see anything like that in the javascript doc but ...
Or if anyone has a good idea about how to achieve this, it would be most welcome.
Thank you,
[B]
I have a series of words (server-side generated) that counts about 300 items (but likely to grow in time), and I would like to check (client side) whether what the user typed in a certain field matches one of the words in the series.
To do this, I know I can put that series of words in a javascript array, then iterate through the array and test each word for equivalence to the user input.
Or maybe put all the words in one long string and then use regexp.
As for the first option, I'm afraid of the time cost if the series of words gets bigger.
As for the second option, as I don't know the content of the series of words and the user input, I think it could be a bit tricky.
I was wondering if there was a javascript equivalent to the Java "List" object (or, more precisely, "ArrayList", as "List" is an interface), which has a method "contains()" that exactly fits my need. I didn't see anything like that in the javascript doc but ...
Or if anyone has a good idea about how to achieve this, it would be most welcome.
Thank you,
[B]