Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two data structures in javascript, arrays and objects (actually, arrays are a special kind of object, but don't be concerned about that for now). An array is a collection with integer keys; the keys may be non-contiguous (i.e. they don't need to go 0,1,2,3, they might go 0,51,52,99,102). You can assign named properties to an array, but that makes iterating over them more difficult.</p> <p>An object is a collection of arbitrarily-named keys that can be accessed very similarly to an array.</p> <p>The simplest way to instantiate an array is as an array literal (which uses the square bracket notation), while the simplest way to create an object is with object literal (which uses curly-bracket notation):</p> <pre><code>var myArray = []; // creates a new empty array var myOtherArray = [ "foo", "bar", "baz"]; // creates an array literal: // myOtherArray[0] === "foo" // myOtherArray[1] === "bar" // myOtherArray[2] === "baz" // // // This would be reasonably called a multidimensional array: // var myNestedArray = [ [ "foo", "bar", "baz"], [ "one", "two", "three"] ]; // myNestedArray[0] =&gt; [ "foo", "bar", "baz"]; // myNestedArray[1] =&gt; [ "one", "two", "three"]; // myNestedArray[0][0] === "foo"; // myNestedArray[1][0] === "one"; var myObject = {}; // creates an empty object literal var myOtherObject = { one: "foo", two: "bar", three: "baz" }; // myOtherObject.one === "foo" // myOtherObject["one"] === "foo" (you can access using brackets as well) // myOtherObject.two === "bar" // myOtherObject.three === "baz" // // // You can nest the two like this: var myNestedObject = { anArray: [ "foo", "bar", "baz" ], anObject: { one: "foo", two: "bar", three: "baz" } } </code></pre>
 

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