An array in JavaScript is a special variable that can hold multiple values in a single variable, instead of storing just one value like a normal variable does.
Basic Example:
let Phones = ["Vivo", "Oppo", "Samsung"];
console.log(fruits[0]); // Vivo
console.log(fruits[1]); // Oppo
console.log(fruits[2]); // Samsung
Key Points:
Index starts at 0 - First item is
array[0], notarray[1]Can hold any data type - Numbers, strings, booleans, objects, even other arrays
.length- Gives the total number of itemsDynamic size - You can add/remove items anytime
Mixed Array:
A mixed array is just an array that stores different data types together in a single array, instead of only numbers or only strings.
Example:
let mixedArray = ["Messi", 22, true, ["Tamil", "English"], { city: "Chennai" }];
Top comments (0)