06 Handout 1
06 Handout 1
Arrays
I. What are Arrays?
It is a common programming mechanic known as a data structure.
It is the simplest data-storing structure in any programming language.
In JS, it allows scripts and applications to store multiple values in a single variable.
A. Accessing Arrays
Array elements can be accessed by referring to their index number written in square
brackets ([ ]).
Index numbers start with zero (0) instead of one (1); the first element of the array is
designated with the index number of zero (0), while the last element is designated by
the total array element value subtracted by one (1) (n – 1, where n stands for the total
array element value).
Attempting to access an array element using an index number HIGHER than the
maximum array element value will return the undefined value.
B. Array Literals
A method of array declaration that allows for greater simplicity, readability, and
execution speed.
Uses a specific syntax for its declaration; the syntax involves the usage of simply the
possible element values enclosed with a pair of square brackets ([ ]).
The array literal syntax is the recommended way to declare arrays, due to its simplicity
and execution speed.
B. Combining Arrays
Arrays can be combined through concatenation.
The concat() method can be used to join two (2) existing arrays to create a new one:
1. The array that uses the concat() method as its object property will become the first
array. The first array will be joined to the second array at its ending element value.
2. The array that is declared as a parameter of the concat() method will become the
second array. The second array is joined to the first array at its beginning element
value.
References:
Sololearn.com. JavaScript Tutorial. Retrieved on April 17, 2018:
https://www.sololearn.com/Course/JavaScript/
Sololearn.com. jQuery Tutorial. Retrieved on April 17, 2018:
https://www.sololearn.com/Course/jQuery/