Example 1 – Array Constructor
1 2 3 | // Declare an array (using the array constructor)var arlene1 = new Array();var arlene2 = new Array("First element", "Second", "Last"); |
Example 2 – Literal notatoin
1 2 3 | // Declare an array (using literal notation)var arlene1 = [];var arlene2 = ["First element", "Second", "Last"]; |
Example 3 – Implicit Declaration
1 2 3 | // Create an array from a method's return valuevar carter = "I-learn-JavaScript";var arlene3 = carter.split("-"); |
1 2 3 | // Declare an empty array using literal notation:var arlene = [];// The variable now contains an array of length zero |
No comments:
Post a Comment