About Lesson
Array Declaration and Initialization
You can create arrays using two common methods:
1. Using Array Literals
This is the simplest way to declare and initialize an array. You directly specify the elements within square brackets [].
Example:
JavaScript
let fruits = ["Apple", "Banana", "Mango"];
console.log(fruits); // Output: ["Apple", "Banana", "Mango"]
2. Using the Array Constructor
You can also create arrays using the Array() constructor, though this is less common.
Example:
JavaScript
let numbers = new Array(10, 20, 30);
console.log(numbers); // Output: [10, 20, 30]