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!