An array is a collection of items stored at a single variable. Arrays can hold any type of data and can be accessed using their index.
// Method 1: Using new Array()
let arr1 = new Array(1, 2, 3);
// Method 2: Using []
let arr2 = [4, 5, 6];
let arr = [10, 20, 30];
console.log(arr[0]); // 10
console.log(arr[1]); // 20
console.log(arr[2]); // 30
let nestedArr = [[1, 2], [3, 4]];
console.log(nestedArr[0][1]); // 2
console.log(nestedArr[1][0]); // 3
let arr = [1, 2, 3];
arr[0] = 10;
console.log(arr); // [10, 2, 3]
let arr = [1, 2, 3];
console.log(Array.isArray(arr)); // true
let notArr = 123;
console.log(Array.isArray(notArr)); // false
Click the button to see array operations in action: