JavaScript · Junior · Question 55 of 75

How does find differ from filter?

const users = [{ id: 1 }, { id: 2 }, { id: 2 }];

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.

Further reading

Problem with a question

JavaScript · Junior · question 55

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz