0
0
Javascriptprogramming~5 mins

Find and some methods in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aundefined
Bnull
Cfalse
Dempty array
Which method returns a boolean indicating if any array element passes a test?
Asome()
Bfind()
Cfilter()
Dmap()
What will [2, 4, 6].some(x => x > 5) return?
Aundefined
Bfalse
Ctrue
D6
Which method would you use to get all elements that match a condition?
Afind()
Bsome()
Creduce()
Dfilter()
If you want only the first matching element from an array, which method is best?
Afilter()
Bfind()
Csome()
Dmap()
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.