Object Iteration

Learn about some methods and object iteration.

The find() method

The find() method works in a similar way to the filter() method, but it returns the first value that matches the criteria defined in the callback. For example, the following code returns the first number that’s greater than 22:

Press + to interact
console.log([1, 2, 3, 4].find(x => x > 2));

The following code finds the first programming language that begins with the letter “J”:

Press + to interact
console.log(['C', 'C++', 'Ruby', 'Python', 'JavaScript', 'Swift', 'Java'].find(word => word.startsWith('J')));

We can use this to find people in our people array from the Guess Who? game that match the given criteria. The ...