# Array.filter()

{% embed url="<https://replit.com/@bgoonz/array-methods#index.js>" %}

### filter() <a href="#id-94ae" id="id-94ae"></a>

```
const array = [1, 2, 3, 4]const filteredArray = array.filter(element => element%2)// array = [1, 2, 3, 4]// filteredArray = [1, 3]
```

**`filter`** method will return a brand new array with elements that returned `true`\_ \_from the function provided. Notice that in the example above, the function passed into the filter method returns `true` if element is odd which is why you see that `filteredArray` is `[1, 3]`.

**`Note`**: filter method doesn’t mutate the original array. It will create a new array.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bryan-guner.gitbook.io/my-docs/array-methods-lesson/methods/array.filter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
