Category: javascript
what is array
Published on 16 Jul 2026
Explanation
An array is a collection of multiple values stored in a single variable. Each value is accessed using its index.
Code:
const fruits = ['Apple', 'Banana', 'Orange']; console.log(fruits[0]);
Explanation
The push() and pop() methods add and remove elements from the end of an array.
Code:
let numbers = [10, 20]; numbers.push(30); numbers.pop();
Explanation
The shift() and unshift() methods remove and add elements at the beginning of an array.
Code:
let colors = ['Red', 'Blue'];
colors.unshift('Green');
colors.shift();
Explanation
The map() method creates a new array by transforming each element.
Code:
const nums = [1,2,3]; const doubled = nums.map(n => n * 2);
Explanation
The filter() method returns elements that satisfy a given condition.
Code:
const ages = [12,18,25]; const adults = ages.filter(age => age >= 18);