Arrays are one of the most common things that you’re going to use as a programmer. So, I’m going to explain nine JavaScript array methods that are going to make your life so much easier and more enjoyable.

To get started I just have an array of items, that we’re going to use for all these different array methods. Without wasting much time, let’s dive deep in to the pool of arrays (wink…)

const arrayItems = [
  {name: 'cheese cake', price: 25},
  {name: 'ham burger', price: 30},
  {name: 'cheesy tacos', price: 20},
  {name: 'beef burito', price: 18},
  {name: 'maxican chille rice', price: 15},
  {name: 'hot chocolate', price: 12},
  {name: 'apple frudge', price: 28},
  {name: 'chicken lassagna', price: 35},
]

filter() method

So let’s assume that we want to get all the items in this list that are less than or equal to 26 dollars of price. All we need to use is the filter method to filter out everything that’s under 26 dollars. So, let’s just say that, we have a variable which is going to be filteredItems. The filter method just takes a single function which is going to have one parameter.

const filteredItems = arrayItems.filter((item) => {
  return item.price <= 26;
})

#web-development #javascript #arrays #array-methods

9 Must Know JavaScript Array Methods
13.70 GEEK