Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following code creates an Array object called myCars:</p> <pre><code>var myCars=new Array(); </code></pre> <p>There are two ways of adding values to an array (you can add as many values as you need to define as many variables you require).</p> <p>1:</p> <pre><code>var myCars=new Array(); myCars[0]="Saab"; myCars[1]="Volvo"; myCars[2]="BMW"; </code></pre> <p>You could also pass an integer argument to control the array's size:</p> <pre><code>var myCars=new Array(3); myCars[0]="Saab"; myCars[1]="Volvo"; myCars[2]="BMW"; </code></pre> <p>2:</p> <pre><code>var myCars=new Array("Saab","Volvo","BMW"); </code></pre> <p><strong>Note:</strong> If you specify numbers or true/false values inside the array then the type of variables will be numeric or Boolean instead of string.</p> <p><strong>Access an Array</strong></p> <p>You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0.</p> <p>The following code line:</p> <pre><code>document.write(myCars[0]); </code></pre> <p>will result in the following output:</p> <pre><code>Saab </code></pre> <p><strong>Modify Values in an Array</strong></p> <p>To modify a value in an existing array, just add a new value to the array with a specified index number:</p> <pre><code>myCars[0]="Opel"; </code></pre> <p>Now, the following code line:</p> <pre><code>document.write(myCars[0]); </code></pre> <p>will result in the following output:</p> <pre><code>Opel </code></pre>
    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