DEV Community

Cover image for Array in Javascript...
Parthipan M
Parthipan M

Posted on

Array in Javascript...

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
Enter fullscreen mode Exit fullscreen mode

Key Points:

  • Index starts at 0 - First item is array[0], not array[1]

  • Can hold any data type - Numbers, strings, booleans, objects, even other arrays

  • .length - Gives the total number of items

  • Dynamic 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" }];
Enter fullscreen mode Exit fullscreen mode

Top comments (0)