Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the difference between objects and associated array in javascript?
    primarykey
    data
    text
    <h2>The Confusing discussion</h2> <p><a href="https://stackoverflow.com/questions/8145797/how-do-i-put-an-objectassociatvie-array-in-an-objectassociatve-array/8145831#comment9998076_8145831">In this question</a>, there is a discussion on the concepts of associated array and object in javaScript which I got a bit confused.</p> <p>In this example code:</p> <pre><code>var check = { pattern : { name: /^[a-zA-Z-\s]{1,20}$/, email: /^[a-zA-Z0-9._(-)]+@[a-zA-Z0-9.(-)]+\.[a-zA-Z]{1,4}$/, pass: /.{6,40}/, url: /^[(-)\w&amp;:\/\.=\?,#+]{1,}$/, aml: /&lt;(.+)_([a-z]){1}&gt;$/ } }; </code></pre> <p>Here is the discussion makes me confused:</p> <blockquote> <p>@steven.yang the outer object is not an associative array in your sample, but that is what is being asked for</p> <p>@sissonb what do you mean by 'outer object is not an associative array'? I think associated array is expressed as object in javascript. The difference is in the notation - either through <code>foo.bar</code> or <code>foo[bar]</code></p> <p>@steven.yang associated array means key => value. <a href="http://en.wikipedia.org/wiki/Associative_array" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Associative_array</a> Your inner object has a key of pattern, the object containing this associative array has no key.</p> </blockquote> <h2>My Understanding of Associated Array and Objects in JS</h2> <p>Associated array is <a href="http://en.wikipedia.org/wiki/Associative_array" rel="nofollow noreferrer">defined as</a> key-value pairs which is expressed as the <code>object</code> in JavaScript.</p> <p>The outer object assigned to <code>check</code> has a key <code>pattern</code> and an value of another object. The inner object has keys of <code>name</code>, <code>email</code> ... and corresponding values of regular expression objects.</p> <p>Could both objects be counted as associative arrays?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload