Get up to 80 % extra points for free! More info:

Lesson 19 - Advanced Array Methods In JavaScript

In the previous lesson, Arrow Functions And Modern Event Handling In JavaScript, we introduced arrow functions. We already know that they offer us a shorter syntax and maintain the context of the this keyword in classes. We also showed a little hack how to avoid the that variable when handling DOM events and keep the element that triggered the event. Today, we're going to continue with arrow functions and learn how to use them to work with arrays.

Advanced Array Methods In JavaScript

Now let's look at methods that allow arrow functions to be used when working with arrays. Some came up with ES6, some have been here since ES5 and were initially designed to receive a function. Let's show them.

filter()

This method is used when we need to filter certain items from an array. The filter() method takes a function as a parameter that is automatically called for each item of the array. In this function, we return true if the item passed as a parameter meets our criteria. The filter() method then stores the matching items to a new array and returns it.

Example

Here's an example where we want to select only those numbers that are divisible by 2:


 

...End of the preview...
Continue further

You will gain knowledge worth hundreds of thousands for a few crowns

You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.

Buy this course

Buy all currently available lessons with exercise submitting and other features for just $7.20
Current account balance $0
By buying this package, you'll have access to all 20 articles (20 lessons) in this course.

This article is licensed: Premium, by buying this article, you agree with the terms of use.

What will you get from us in the next lessons?
  • Unlimited and permanent access to individual lessons.
  • High quality IT knowledge.
  • Skills to help you get your dream and well-paid job.

Article description

Requested article covers this content:

In this tutorial, we'll introduce advanced array methods in JavaScript and try them on examples using arrow functions.

You gain credits by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.

Article has been written for you by Štěpán Zavadil
Avatar
Activities