Skip to main content

Command Palette

Search for a command to run...

6 New Array Functions in ES6

JavaScript built-in array methods

Updated
3 min read
6 New Array Functions in ES6
B

🚀 Welcome, Frontend Learners! Hey there 👋 I’m Bhushan Patil, and I’m on a mission to make learning JavaScript, React, and frontend development simpler, faster, and more project-driven.

🎯 Whether you're just starting out or looking to level up, this page is your go-to resource:

🔥 Free coding tips & tricks

💻 Hands-on projects to build your portfolio

📽️ In-depth YouTube tutorials

💬 A supportive Telegram community

🧠 Smart advice to help you grow daily

If you're serious about becoming a skilled frontend developer, you're in the right place.

👉 Start by watching a free project tutorial, or join the community on Telegram to ask questions, share progress, and stay motivated.

Let’s build amazing things together 💪

ES6, also known as ECMAScript 2015, brought several new features to JavaScript, including new array functions. In this blog, we'll take a look at six of these new functions and how they can make your life easier when working with arrays in JavaScript.

USING MAP()

Definition and Usage

The map() the method creates a new array with the results of calling a function for every array element.

The map() method calls the provided function once for each element in an array, in order.

Note: map() does not execute the function for array elements without values.

Note: this method does not change the original array.

JavaScript map vs for loop

USING FOREACH()

Definition and Usage

The forEach() method calls a function once for each element in an array, in order.

Note: the function is not executed for array elements without values.

JavaScript forEach vs for loop

USING FILTER()

Definition and Usage

The filter()the method creates an array filled with all array elements that pass a test (provided as a function).

Note: filter() does not execute the function for array elements without values.

Note: filter() does not change the original array.

JavaScript filter vs for loop

USING REDUCE()

Definition and Usage

The reduce() the method reduces the array to a single value.

The reduce() the method executes a provided function for each value of the array (from left to right).

The return value of the function is stored in an accumulator (result/total).

Note: reduce() does not execute the function for array elements without values.

Note: this method does not change the original array.

JavaScript reduce vs for loop

USING SORT()

Definition and Usage

The sort() method sorts the items of an array.

The sort order can be either alphabetic or numeric, and either ascending (up) or descending (down).

By default, the sort() method sorts the values as strings in alphabetical and ascending order.

Note: This method changes the original array.

JavaScript sort vs for loop

USING FINDINDEX()

Definition and Usage

The findIndex() the method returns the index of the first element in an array that passes a test (provided as a function).

The findIndex() the method executes the function once for each element present in the array:

  • If it finds an array element where the function returns a true value, findIndex() returns the index of that array element (and does not check the remaining values)

  • Otherwise, it returns -1

Note: findIndex() does not execute the function for array elements without values.

Note: findIndex() does not change the original array.

JavaScript findIndex vs for loop

In conclusion, these six new array functions in ES6 provide a powerful and convenient set of tools for working with arrays in JavaScript. They allow you to perform common array operations with greater ease and make your code more concise and readable. Whether you're just starting out with JavaScript or are an experienced developer, it's worth taking some time to learn these functions and incorporate them into your workflow.

Thank you for reading!

Javascript

Part 7 of 7

Core JavaScript Fundamentals" is a comprehensive series designed to help learners of all levels develop a deep understanding of the fundamental concepts and principles of the JavaScript language.

Start from the beginning

100+ JavaScript Snippets for Beginners: Simplify Your Coding Journey

Make learning JavaScript easier with our collection of 100+ beginner-friendly code snippets. Explore our comprehensive guide now and enhance coding,

More from this blog

Learn about HTML, CSS, JavaScript, React, Vue, Angular, Jest, and more!

18 posts

Subscribe to get a weekly newsletter with amazing tips, tricks, and articles on web development directly in your inbox