Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For starters, in JavaScript (ES5), there isn't such a thing as "Integer". JavaScript (ES5) only has Numbers. </p> <p>Second, in JavaScript there is a lot of implicit type-casting going on. Here is an example:</p> <pre><code>if(1=='1') console.log('very truthy'); </code></pre> <p>If you use a double-equals, it will cast the '1' to a Number and then it will compare the new value (1) to the 1 (which will be true, 1 == 1), and will then log the string 'very truthy'. </p> <p>If you use triple-equals, the implicit type-casting won't happen. </p> <pre><code>if(1==='1') console.log("this won't get logged"); </code></pre> <p>Using the triple-equals prevents the type casting from happening. </p> <p>Next, when you add a value to a whole number index of an array, that index gets updated with the value you tell it to, AND THE LENGTH will get updated. </p> <pre><code>var a = []; a[0] = 0 a[1] = 1; a[2.0] = 2; //[undefined, 1, 2] </code></pre> <p>When you try to update an index that isn't a whole number (1.1), it will convert whatever that is to a string (1.1 becomes '1.1') and then it adds a new custom property to the array and set's the value on it. Custom properties of an array won't affect it's length. </p> <pre><code>var a = []; a[1.1] = 1.1; a.prop = "property"; //[], empty array console.log(a.prop, a['1.1']); //"property",1.1 </code></pre> <p>When you add a custom property to a JS array it mutates the object to then act like an object literal. </p> <p>So in your case here, you end up with an array-ish/object-literal-ish mashup object. NOTE: If you add a custom property to a JS Number or String, they are NOT converted to Object Literals. This behavior that you are exploring is unique to JS arrays. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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