The filter() method creates a new array with all elements that pass the test implemented by the provided function.
Example:
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
//Output: Array ["exuberant", "destruction", "present"]
Top comments (2)
These ES6 JavaScript Array Methods really make our work less tedious.
Yes, ES6 has made our job easier.