In this story, we will see about the different methods in JavaScript to search an item in an array.
There are four different methods to search an array in JavaScript. They are as follows:
From the above different methods, we want to choose the method depends upon our usecase.
Now let’s get deep into the topic.
Array.filter() method is used to find an element in an array under specific condition. Let’s see an example that print all the elements in an array of number that is greater than 10.
const array = [10, 11, 3, 20, 5];
const greaterThanTen = array.filter(element => element > 10);
console.log(greaterThanTen) //[11, 20]
Syntax:
let newArray = array.filter(callback);
Where
#web-development #javascript #nodejs #array-methods