DEV Community

Madhavan G
Madhavan G

Posted on

ARRAY

Simple Definition
An array in JavaScript is a special variable used to store multiple values in a single variable.
Example:
let marks = [85, 90, 78, 92];
Here:
1.Marks is an array
2.It contains 4 values
3.Each value has a position (index)

Index:
Array values are stored with index numbers starting from 0
Example:
let fruits = ["apple", "banana", "mango"];

console.log(fruits[0]); // apple
console.log(fruits[1]); // banana
console.log(fruits[2]); // mango

Why we use Arrays

Instead of this ❌:
let a = 10;
let b = 20;
let c = 30;

We use array ✅:
let numbers = [10, 20, 30];
This makes code:
*Cleaner
*Easier to manage
*Faster to work with loops

Key Features:
Can store different data types
let data = [10, "hello", true];
*Dynamic (can grow/shrink)
*Access using index

Top comments (0)