Array Methods! Pt. 1 (filter, map)

Arrays are common in almost every coding language. What is an array? W3 schools define an array as a special variable that can hold more than one value at a time. This is important within Javascript because we need to have our values and objects be organized within certain areas of code. With arrays being common, theres methods that you can use to help make your project more easier to create or just have an easier time accessing certain data within arrays.

Starting off with the filter method, filter seems very self explanatory; we filter anything we’d like from the array.

filter method

The example above shows that I have an array of sneakers that holds four sneaker values. What is then done is that we create a const named filteredSneakers and have it set the filter method which creates an arrow function to return sneakers that’s price is equal to or lower than two hundred. I console.log the const and then shows what the results that the method has filtered out.

One of the most common methods I’ve used was map. The map method mutates an array and returns a new array of whatever value you want.

map Method

With the example above, we haven’t changed much at all. We only changed the method being used and then just used the argument and set it to a key of name which then prints out the results we see on line 14 and beyond when using console.log.

Thats all of the methods I will be discussing about for now! Short and sweet is how I assume most readers would like it. I will be writing more methods for arrays in future blogs so keep on the look out. Once again thank you so much for reading! Keep coding on!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Webpack bundling as a service

Laravel FormRequest Takes Me To The Homepage ERROR Solution

Creating Toast API with React Hooks

Keeping up with LTS Node

An introduction to React Hooks (JavaScript) — Part 1

Authorisation and Obfuscation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
David Lago

David Lago

More from Medium

JavaScript “this” keyword — Basic explanation

The Most Useful Array Methods in JavaScript: forEach(), map(), filter() and reduce()

What is the Closure & JavaScript ?

JavaScript Declare VS Assign