📦 JavaScript Array Methods

Last Updated: 15th October 2025


Arrays are used to store multiple values in a single variable — and JavaScript gives many built-in methods to work with them easily (add, remove, search, copy, etc.).

Hinglish Tip 🗣: Array methods ko samjho jaise tools — data (items) par different kaam karne ke liye use hote hain.


🧰 Array Methods

MethodPurpose
push()Add element at end
pop()Remove element from end
unshift()Add element at start
shift()Remove element from start
concat()Join two arrays
indexOf()Find first index of a value
includes()Check if value exists
reverse()Reverse array order
join()Convert array to string
slice()Copy part of array
splice()Add/remove items

✏ Example

let nums = [10, 20, 30, 40, 50];

nums.push(60); // [10, 20, 30, 40, 50, 60]
nums.pop(); // [10, 20, 30, 40, 50]
nums.unshift(5); // [5, 10, 20, 30, 40, 50]
nums.shift(); // [10, 20, 30, 40, 50]

let newArray = nums.concat([70, 80]);
console.log(newArray); // [10, 20, 30, 40, 50, 70, 80]

console.log(nums.indexOf(40)); // 3
console.log(nums.includes(30)); // true

let reversed = nums.reverse(); // [50, 40, 20, 10]
console.log(reversed);

let joined = nums.join("-"); // "10-20-40-50"
console.log(joined);

let part = nums.slice(1, 3); // [20, 30]

nums.splice(2, 1); // removes 30 → [10, 20, 40, 50]

⚙️ Utility Array Methods

MethodPurpose
Array.isArray()Check if variable is array
toString()Convert to string (comma separated)
fill()Fill all elements with a static value
flat()Flatten nested arrays (1 level)
from()Create an array from an iterable
of()Create an array from arguments

Array.from() — Create an Array from an Iterable

Creates an array from an iterable object.

let str = "Hello";
let chars = Array.from(str);
console.log(chars);

// Output: ["H", "e", "l", "l", "o"]

Array.of() — Create an Array from Arguments

Creates an array from one or more arguments.

let nums = Array.of(1, 2, 3);
console.log(nums);

// Output: [1, 2, 3]

Example

console.log(Array.isArray([1, 2, 3])); // true
console.log([1, 2, 3].toString()); // "1,2,3"
console.log([1, 2, 3].fill(0)); // [0,0,0]
console.log([1, [2, 3]].flat()); // [1,2,3]

💡 Quick Practice

  • Create an array fruits = ["apple", "banana", "mango"]
  • Add "orange" at end and "grapes" at start
  • Remove last fruit
  • Find index of "banana"
  • Join all fruit names with commas
  • Exercises Set 1
  • Exercises Set 2