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

Costly Linux Mistakes Beginners Make

1. Running Everything as Root One of the biggest beginner errors. Many new users log…

12 hours ago

How Keyloggers Work

A keylogger is a type of surveillance software or hardware that records every keystroke made…

6 days ago

JavaScript Memoization

In JavaScript, it’s commonly used for: Recursive functions (like Fibonacci) Heavy calculations Repeated API/data processing…

4 weeks ago

CSS Container Queries: Responsive Design That Actually Makes Sense

For years, responsive design has depended almost entirely on media queries. We ask questions like: “If…

4 weeks ago

Cron Jobs & Task Scheduling

1. What is Task Scheduling? Task scheduling is the process of automatically running commands, scripts,…

4 weeks ago

Differences Between a Website and a Web App

Here’s a comprehensive, clear differentiation between a Website and a Web App, from purpose all the…

1 month ago