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'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
This article is licensed: Premium, by buying this article, you agree with the terms of use.
- 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.