Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 5.3 — Searching Arrays
JavaScript · Example 3 of 3

some stops as soon as it knows

some stopped at 50 (found one); every stopped at 50 too (found an exception). Neither looked at 7 or 90.

indexOf and includes look for an exact value, find and findIndex look for the first item that passes a test you write (findLast searches from the end), and some and every answer yes-or-no questions about the whole array.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Given const words = ["apple", "Banana", "cherry"];, print whether any word starts with a capital letter, and the index of the first such word.

02

Write hasDuplicate(arr) that returns true if any value appears twice, using indexOf and some.

Explain it without notes

01

What is the difference between indexOf and includes, including how they handle NaN?

02

When would you use find instead of indexOf?

03

What do some and every return for an empty array, and why?

04

Why does [{ a: 1 }].includes({ a: 1 }) return false?

some stops as soon as it knows

Console

(nothing was printed)

Expected console output

true [ 3, 50 ]
false [ 3, 50 ]