Recall & Review
beginner
What does the
find() method do in JavaScript arrays?The
find() method returns the first element in an array that satisfies a given condition (a test function). If no element matches, it returns undefined.Click to reveal answer
beginner
What is the purpose of the
some() method in JavaScript arrays?The
some() method checks if at least one element in the array passes a test function. It returns true if any element matches, otherwise false.Click to reveal answer
intermediate
How does
find() differ from filter()?find() returns only the first matching element, while filter() returns all matching elements as a new array.Click to reveal answer
beginner
What will
some() return if the array is empty?It will return
false because there are no elements to satisfy the condition.Click to reveal answer
beginner
Write a simple example using
find() to get the first even number from [1, 3, 4, 6].<pre>const numbers = [1, 3, 4, 6];
const firstEven = numbers.find(num => num % 2 === 0);
console.log(firstEven); // Output: 4</pre>Click to reveal answer
What does
find() return if no element matches the condition?✗ Incorrect
find() returns undefined when no element satisfies the condition.Which method returns a boolean indicating if any array element passes a test?
✗ Incorrect
some() returns true or false depending on whether any element passes the test.What will
[2, 4, 6].some(x => x > 5) return?✗ Incorrect
Since 6 is greater than 5,
some() returns true.Which method would you use to get all elements that match a condition?
✗ Incorrect
filter() returns all elements that satisfy the condition as a new array.If you want only the first matching element from an array, which method is best?
✗ Incorrect
find() returns the first element that matches the condition.Explain how the
find() method works and give an example.Think about searching for something in a list and stopping when you find it.
You got /3 concepts.
Describe the difference between
some() and find() methods.One tells you if something exists, the other gives you the actual item.
You got /4 concepts.