JavaScript · Junior · Question 55 of 75
How does find differ from filter?
const users = [{ id: 1 }, { id: 2 }, { id: 2 }];- ✓Correct answer:
findreturns the first matching element (orundefined);filterreturns an array of all matches - 2They are identical
- 3
findreturns the index of the element
Explanation
users.find(u => u.id === 2) gives one object and stops early; users.filter(...) always scans the whole array. findIndex returns the index instead.