Categories: javascript

Array Filter Method

The Array filter method is used to check against a given condition.

Task: print out all multiples of 3 in the given array:

let x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

Answer:

let x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

mulValue = (val) => {
return val % 3 === 0;
}

let result = x.filter(mulValue);
alert(result) // 3,6,9,12,15

Recent Posts

JavaScript Variables

1. What Is a Variable in JavaScript? A variable is a named container used to store data…

7 hours ago

C++ Queue

1. What Is a Queue? A Queue is a linear data structure that follows the principle: FIFO – First…

1 day ago

Must-Know Angular Concepts

Angular is a full-featured frontend framework built by Google for creating large, maintainable, and high-performance web applications.…

3 days ago

Responsive Web Design (RWD)

What Is Responsive Web Design? Responsive Web Design (RWD) is an approach to building websites…

3 days ago

Geolocation API in JavaScript

The Geolocation API allows a web application to access a user’s geographical location (latitude, longitude, and more), with…

1 week ago

The Golden Ratio (φ)

1. What Is the Golden Ratio? The Golden Ratio, represented by the Greek letter φ (phi), is…

2 weeks ago