I have such an array:
arr['key1'] = true;
arr['key2'] = true;
arr['key3'] = true;
...
arr['keyN'] = true;
How to determine, have anyone key a "false" value?
I have such an array:
How to determine, have anyone key a "false" value? |
||||
Unfortunately, the only way to do this until recently was to loop through the array; if you're using this in a browser-based app, you'll probably have to do it that way. There are new array features in ECMAScript 5th edition (the new JavaScript) that let you do this in a slightly different way, but only some browsers support them (and I'm not sure they'd necessarily be applicable). But what you've described in your question is more a map (or "dictionary;" sometimes called an associative array) than an array (numerically-based indexed thingy). In JavaScript, "array" is usually used to mean numerically-indexed arrays (e.g., created via
...whereas this is an object ("map", "dictionary", "associative array"):
Your use of non-numeric indexes suggests you're really using a map, not an array. The search loop looks something like this on maps:
There I've used |
||||
|
are you new to Javascript?
|
|||||||||||||
|
This returns as soon as a single false is found. |
||||
|
true
andfalse
though). – Felix Kling Apr 7 '10 at 10:29