The filter() method creates a new array with all elements that pass the test implemented by the provided function.
Does filter create a new array JavaScript?
The filter() method creates a new array with all the elements that pass the test implemented by the callback() function. Internally, the filter() method iterates over each element of the array and pass each element to the callback function.
Does filter affect array?
Yes, . filter creates a new array, but the new array is the only new structure that is created. The items inside the array remain unchanged. With your code, after filtering, you have a new array which contains 2 items, where both of those items are references to the same objects that were in the original array.