- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Array filter
JavaScript Arrays
JavaScript Array filter
JavaScript
filterbuilds a new array containing only the elements that pass a test.
The callback returns true to keep an element and false to drop it.
The new array can be shorter than the original, but never longer.
Example
Example
javascript
const numbers = [1, 8, 3, 12];
console.log(numbers.filter(n => n > 4).join(","));