Compare Revisions

Array

Revision 493053:

Revision 493053 by Airblader on

Revision 496963:

Revision 496963 by kiteroa on

Title:
Array
Array
Slug:
Web/JavaScript/Reference/Global_Objects/Array
Web/JavaScript/Reference/Global_Objects/Array
Tags:
"Array","JavaScript Reference","JavaScript"
"Array","JavaScript Reference","JavaScript"
Content:

Revision 493053
Revision 496963
n42      Note that <a class="external" href="http://www.andrewdupontn42      Some people think that <a class="external" href="http://www
>.net/2006/05/18/javascript-associative-arrays-considered-harmful/>.andrewdupont.net/2006/05/18/javascript-associative-arrays-consid
>">you shouldn't use an array as an associative array</a>. You can>ered-harmful/">you shouldn't use an array as an associative array
> use plain <a href="/en-US/docs/JavaScript/Reference/Global_Objec></a>. In nay case, you can use plain <a href="/en-US/docs/JavaScr
>ts/Object" title="JavaScript/Reference/Global Objects/Object">obj>ipt/Reference/Global_Objects/Object" title="JavaScript/Reference/
>ects</a> instead, although doing so comes with its own caveats. S>Global Objects/Object">objects</a> instead, although doing so com
>ee the post <a class="external" href="http://www.less-broken.com/>es with its own caveats. See the post <a class="external" href="h
>blog/2010/12/lightweight-javascript-dictionaries.html" title="htt>ttp://www.less-broken.com/blog/2010/12/lightweight-javascript-dic
>p://monogatari.doukut.su/2010/12/lightweight-javascript-dictionar>tionaries.html" title="http://monogatari.doukut.su/2010/12/lightw
>ies.html">Lightweight JavaScript dictionaries with arbitrary keys>eight-javascript-dictionaries.html">Lightweight JavaScript dictio
></a> as an example.>naries with arbitrary keys</a> as an example.
n63      Note that there is nothing unique about JavaScript arrays an63      Note that there is nothing unique about JavaScript arrays a
>nd their properties that causes this. JavaScript properties that >nd their properties that causes this. JavaScript properties that 
>begin with a digit cannot be referenced with dot notation. They m>begin with a digit cannot be referenced with dot notation; they m
>ust be accessed using bracket notation. For example, if you had a>ust be accessed using bracket notation. For example, if you had a
>n object with a property "3d", it too would have to be referenced>n object with a property "3d", it would have to be referenced usi
> using bracket notation, not dot notation. This similarity is exh>ng bracket notation, not dot notation. This similarity is exhibit
>ibited in the following two code samples:>ed in the following two code samples:
t88    <h3 id="Relationship_between_length_and_numerical_properties"t88    <p id="Relationship_between_length_and_numerical_properties">
>> 
89      Similarly, object properties which happen to be reserved wo
 >rds(!) can only be accessed as string literals; this means that b
 >racket notation must be used.
90    </p>
91    <pre class="brush: js">
92var promise = {'var'  : 'text',
93               'array': [1, 2, 3, 4] }
94 
95console.log(promise['array'])
96</pre>
97    <h3>

Back to History