100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
JavaScript

Common Array Methods in JavaScript

Explore the most-used array methods, split into mutating methods that change the original array and non-mutating methods that return a new array.

Objects & ArraysIntermediate12 min readJul 8, 2026
Analogies

1. Introduction

JavaScript arrays come with a rich set of built-in methods for adding, removing, transforming, and searching elements. Some of these methods mutate (change) the original array in place, while others are non-mutating and instead return a brand-new array, leaving the original untouched. Knowing which is which is essential for writing predictable code, especially when working with frameworks that rely on immutability (like React).

🏏

Cricket analogy: Think of a scorecard: some updates like editing a player's live score mutate the original sheet, while others, like a broadcaster printing a fresh summary sheet for TV graphics, leave the original scorebook untouched.

2. Syntax

javascript
// Mutating: changes the original array
arr.push(item);
arr.pop();
arr.splice(start, deleteCount, ...items);
arr.sort(compareFn);

// Non-mutating: returns a new array
const mapped = arr.map(fn);
const filtered = arr.filter(fn);
const piece = arr.slice(start, end);
const combined = arr.concat(otherArr);

3. Explanation

Mutating Methods

Mutating methods change the array they are called on and typically return either the removed element(s) or the new length, rather than the modified array itself. Common examples: push/pop (add/remove from the end), shift/unshift (add/remove from the start), splice (insert/remove at any position), sort (reorders in place), and reverse. Because these change the original array, they can cause subtle bugs if other parts of your program still hold a reference to that same array and expect it not to change.

🏏

Cricket analogy: Virat Kohli substituting himself onto the field mid-over or being run out changes the actual playing XI list, and if the scorer and commentator both reference the same team sheet, one's edit surprises the other.

Non-Mutating Methods

Non-mutating methods leave the original array untouched and instead return a new array (or a single value). Common examples: map (transform each element), filter (keep elements matching a condition), slice (extract a portion), concat (merge arrays), and reduce (fold into a single value). These are preferred in modern JavaScript and frameworks like React because they avoid unexpected side effects and make data flow easier to reason about.

🏏

Cricket analogy: Filtering a squad list down to only players with a century this season, or mapping each player's name to their strike rate, produces a brand-new list for the display board without touching the original roster.

Gotcha: sort() and splice() mutate in place even though they "look" like they might return a transformed copy — always double-check a method's documentation if you're unsure. If you need a sorted copy without touching the original, sort a copy first: [...arr].sort(...).

4. Example

javascript
const numbers = [5, 3, 8, 1];

// Mutating methods change the original array
const popped = numbers.pop();
numbers.push(10);
numbers.sort((a, b) => a - b);
console.log(numbers);
console.log(popped);

// Non-mutating methods return a new array
const original = [1, 2, 3];
const doubled = original.map(n => n * 2);
const evens = original.filter(n => n % 2 === 0);
const sliced = original.slice(1);

console.log(doubled);
console.log(evens);
console.log(sliced);
console.log(original);

5. Output

text
[ 3, 5, 8, 10 ]
1
[ 2, 4, 6 ]
[ 2 ]
[ 2, 3 ]
[ 1, 2, 3 ]

6. Key Takeaways

  • Mutating methods (push, pop, shift, unshift, splice, sort, reverse) change the original array in place.
  • Non-mutating methods (map, filter, slice, concat, reduce) return a new array/value and leave the original untouched.
  • sort() mutates in place and sorts lexicographically by default unless given a compare function.
  • Use [...arr] or arr.slice() to copy an array before applying a mutating method if you need to preserve the original.
  • Non-mutating methods are preferred when working with immutable state patterns (e.g. React state updates).

Practice what you learned

Was this page helpful?

Topics covered

#JavaScript#JavaScriptProgrammingStudyNotes#Programming#CommonArrayMethodsInJavaScript#Common#Array#Methods#Syntax#Functions#DataStructures#StudyNotes#SkillVeris