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

PGP Encryption And How It Works

Pretty Good Privacy (PGP) is one of the most widely used encryption systems for securing emails,…

18 hours ago

How To Migrate from PostgreSQL to MySQL

Database migration is one of the most challenging tasks in software engineering. While both PostgreSQL…

5 days ago

Hidden Gems Inside Modern JavaScript

Modern JavaScript isn’t just let, const, arrow functions, and promises anymore. Over the years, the language has…

5 days ago

Software Developer Pain Points Ranked: What Frustrates Developers the Most?

Software development is one of the most rewarding careers in technology, but it is also…

6 days ago

How to Print Documents in JavaScript

Printing a document in JavaScript usually means triggering the browser’s print dialog and controlling what…

1 week ago

CSS Display Cheatsheet

The display property controls how an element behaves in the layout and how its children are arranged. Access software…

2 weeks ago