Back to JavaScript Cheat Sheet

The Ultimate JavaScript Array Methods Cheat Sheet

Learn how to use array methods with our comprehensive javascript array method cheat sheet. Covering all the methods you need to know in order to become a better JavaScript developer.
6 min readLogan FordLogan Ford

The Most Comprehensive JavaScript Array Methods Cheat Sheet

Are you looking for the best JavaScript array methods cheat sheet? We got you covered. Check out our free JavaScript array tutorial for beginners and learn how to use arrays in JavaScript in no time.

What is an array in JavaScript?

In JavaScript, an array is a fundamental data structure used to store multiple values in an ordered list. Learning about arrays is crucial for web development, as they help in managing and manipulating data efficiently.

Declaring Arrays in JavaScript

The most common way to declare an array in JavaScript is to use the [] syntax.

1const numbers = [1, 2, 3, 4, 5];
2
3const fruits = ['apple', 'banana', 'cherry'];

Common JavaScript Array Methods

JavaScript provides various built-in methods for manipulating arrays. Mastering these will help you in JavaScript programming classes and real-world projects.

Adding & Removing Elements

  • push() – Adds elements to the end.
  • pop() – Removes the last element.
  • unshift() – Adds elements to the beginning.
  • shift() – Removes the first element.
1const arr = [1, 2, 3];
2
3arr.push(4); // [1, 2, 3, 4]
4arr.pop(); // [1, 2, 3]
5arr.unshift(0); // [0, 1, 2, 3]
6arr.shift(); // [1, 2, 3]

Iterating Over Arrays

  • forEach() – Loops through each item.
  • map() – Creates a new array by applying a function to each element. Read more about map.
  • filter() – Returns a new array with elements that meet a condition. Read more about filter.
  • reduce() – Reduces an array to a single value. Read more about reduce.
1const numbers = [1, 2, 3, 4, 5];
2
3numbers.forEach(num => console.log(num));
4
5const doubled = numbers.map(num => num * 2);
6
7const evens = numbers.filter(num => num % 2 === 0);
8
9const sum = numbers.reduce((acc, num) => acc + num, 0);

Searching & Transforming

  • find() – Finds the first matching element.
  • some() – Checks if at least one element meets a condition.
  • every() – Checks if all elements meet a condition.
  • indexOf() – Finds the index of an element.
  • includes() – Checks if an element exists.
1const nums = [10, 20, 30, 40];
2
3console.log(nums.find(n => n > 25)); // 30
4
5console.log(nums.includes(20)); // true
6
7console.log(nums.indexOf(30)); // 2

Sorting & Reversing

  • sort() – Sorts an array (modifies the original array).
  • reverse() – Reverses the array order.
  • toSorted() (ES2023) – Returns a sorted copy without modifying the original.
1const scores = [40, 10, 100, 50];
2
3scores.sort((a, b) => a - b); // [10, 40, 50, 100]

Removing Duplicates

1const uniqueNumbers = [...new Set([1, 2, 2, 3, 4, 4, 5])]; // [1, 2, 3, 4, 5]

JavaScript Performance Tips

Optimizing your JavaScript code can improve efficiency, especially in web applications and server-side development.

  1. Use push() instead of unshift()push() is faster since it avoids shifting indexes.
  2. Use Set for unique values – More efficient than filtering duplicates manually.
  3. Use map() and reduce() wiselymap() creates a new array, while forEach() modifies in place.
  4. Sort with compare functions – Default sort() converts values to strings, causing incorrect ordering.

JavaScript Array Interview Questions

In your first job interview, 9/10 times you will be asked about arrays. Here are some practice questions to help you prepare for your next interview:

  1. Reverse an array in place – without using .reverse().
  2. Find the missing number in a sequence.
  3. Implement a custom map function that mimics Array.prototype.map.
  4. Rotate an array by k positions.
  5. Find the most frequent element in an array.

Additional JavaScript Resources to Learn Arrays

Looking for the sites to learn JavaScript or JavaScript resources? Check these out these free resources on javascript arrays:

Where to Learn JavaScript for Free

If you're asking "where can I learn JavaScript?", try our free JavaScript tutorial. This JavaScript online class will help you master JavaScript programming step by step.


TechBlitz is the best site to learn javascript, our free course teaches you HTML, CSS and JavaScript. Ensuring you learn the basics and become a better JavaScript developer in no time!

Learn to code, faster

Join 810+ developers who are accelerating their coding skills with TechBlitz.

Share this article