// Declare an array (using the array constructor)
var arlene1 = new Array();
var arlene2 = new Array("First element", "Second", "Last");
We first declared an empty array. We then assigned three elements to the second array, while declaring it. "new Array()" is the array constructor.
ARRAY LITERAL NOTATION
Below, we use an alternate method to declaring arrays:
// Declare an array (using literal notation)
var arlene1 = ;
var arlene2 = ["First element", "Second", "Last"];
We declared above the exact same arrays as previously; instead of new Array(�), you can use square brackets, optionally enclosing elements. Using square brackets (vs. array constructor) is called the "array literal notation."
IMPLICIT ARRAY DECLARATION
// Create an array from a method's return value
var arlene3 = carter.split("-");
- answered 4 years ago
- Gul Hafiz