The filter() method accepts two named arguments: a callback function and an optional object. The Object.values method gives an array, so we can filter that, but in this case we can return if didn’t find anything with the array find method. Encoding failed while adding watermark using ffmpeg in Laravel. 25, Sep 19. filter() does not mutate the array on which it is called. Inside the function, we checked if the population of the each city in the array is greater than 3 million. If we you want to filter based on particular property then we do so by the following method. One of the most common tasks when working with an array is to create a new array that contains a subset of elements of the original array. As you can see, using .reduce() is an easy way to generate a single value or object from an array. Because the filter() method returns an a new array, you can chain the result with other iterative methods such as sort() and map(). A value to be passed to the function to be used as its "this" value. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. log (user. elements without values. name)); // first iteration … link brightness_4 code