JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Array Methods


📘 JavaScript Array Methods – Working with Arrays Easily

JavaScript provides a wide range of built-in methods to manipulate arrays efficiently — from adding/removing items to looping and transforming data.

These methods make array operations cleaner, shorter, and more expressive.


🔹 Commonly Used Array Methods

Method Description Example
push() Adds item(s) to the end of an array arr.push("Orange")
pop() Removes and returns last item arr.pop()
shift() Removes and returns first item arr.shift()
unshift() Adds item(s) to the beginning of an array arr.unshift("Lemon")
splice() Adds/removes items at specific index arr.splice(1, 1)
slice() Returns selected elements (no change to original) arr.slice(1, 3)
concat() Combines two arrays arr1.concat(arr2)
join() Converts array to string with separator arr.join(", ")
indexOf() Finds index of an element arr.indexOf("Apple")
includes() Checks if value exists arr.includes("Mango")
forEach() Executes function on each item (no return) arr.forEach(fn)
map() Transforms array, returns new array arr.map(x => x * 2)
filter() Filters elements based on condition arr.filter(x => x > 10)
reduce() Reduces array to a single value arr.reduce((a, b) => a + b)
find() Finds the first element that satisfies a condition arr.find(x => x > 10)
sort() Sorts array (default is lexicographic) arr.sort()
reverse() Reverses array elements arr.reverse()

🔹 Example

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

// Map
let doubled = numbers.map(n => n * 2);      // [20, 40, 60, 80, 100]

// Filter
let above30 = numbers.filter(n => n > 30);  // [40, 50]

// Reduce
let sum = numbers.reduce((a, b) => a + b);  // 150

// Find
let firstAbove25 = numbers.find(n => n > 25); // 30

Practice Questions

Q1. How do you double all values in an array using a method?

Q2. Which method allows you to filter numbers greater than 50 in an array?

Q3. How do you find the sum of all numbers in an array?

Q4. Which method runs a function on each item but does not return a new array?

Q5. How do you remove the last element of an array?

Q6. What method is used to sort an array alphabetically?

Q7. How do you join elements of an array into a string separated by dashes (-)?

Q8. What method returns the index of a given value in an array?

Q9. How can you combine two arrays without modifying the original ones?

Q10. How do you reverse the order of elements in an array?


JS Array Methods Quiz

Q1: Which method returns a new array with all elements doubled?

A. filter()
B. map()
C. forEach()
D. reduce()

Q2: What does arr.filter(x => x > 5) do?

A. Removes elements
B. Finds index
C. Returns array with elements greater than 5
D. Adds 5 to each element

Q3: Which method is best for calculating the sum of array values?

A. reduce()
B. filter()
C. map()
D. join()

Q4: Which method would you use to loop over each item in an array without returning a new array?

A. map()
B. filter()
C. forEach()
D. find()

Q5: Which method removes elements and modifies the original array?

A. slice()
B. splice()
C. map()
D. concat()

Q6: What will ["a", "b", "c"].reverse() return?

A. ["c", "b", "a"]
B. ["a", "b", "c"]
C. undefined
D. ["a-c-b"]

Q7: Which method checks if an element exists in an array?

A. has()
B. exist()
C. includes()
D. findIndex()

Q8: What will ["x", "y", "z"].join("-") return?

A. ["x-y-z"]
B. x-y-z
C. x,y,z
D. undefined

Q9: Which method finds the first element matching a condition?

A. filter()
B. find()
C. map()
D. includes()

Q10: Which method does not modify the original array?

A. splice()
B. reverse()
C. slice()
D. sort()

Go Back Top