---
title: "What is array filter in JS with example?"  
description: "What is array filter in JS with example?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93740/what-is-array-filter-in-js-with-example  
category: "web application"  
tags: ["javascript", "web application development", "web development"]  
reading_time: 1 minute  

---

# What is array filter in JS with example?

What is [array](https://www.mindstick.com/articles/14/array) [filter](https://www.mindstick.com/forum/1176/filter-in-a-xml-file-in-c-sharp) in JS with example?

## Answers

### Answer by Ethan Karla

An array filter function is used to filter the value with condition from given value. **Syntax:**

```
 array-name.filter([function-name] or [arrow-function]);
```

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
</head>
<body>
<h2>JavaScript Arrays</h2>
    <p>Please enter 10 number for filter </p>
    <p><input type='number' id='num' value='0'></p>
<button onclick='setInArray()'>Try it</button>
<p>Click the button and filter the given list.</p>
<p><input type='number' id='ageToCheck' value='18'></p>
<button onclick='myFunction()'>Try it</button>
<p id='demo'></p>
<script>
const ages = [];
    function checkAge(age) {
        return age > document.getElementById('ageToCheck').value;
    }
    function myFunction() {
        document.getElementById('demo').innerHTML = ages.filter(checkAge);
    }
    function setInArray()
    {
        var nm=document.getElementById('num').value;
        ages.push(nm);
        console.log(ages);
    }
</script>
</body>
</html>
```

Output: ![What is array filter in JS with example?](https://answers.mindstick.com/questionanswer/8927f562-36cf-4c55-ae80-4d8f7fbc2e15/images/b5bf1d9e-bd49-4881-b0f6-12c1f7acde22.png) \


---

Original Source: https://answers.mindstick.com/qa/93740/what-is-array-filter-in-js-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
