1. find returns an element
find runs a predicate and returns the first matching element, or undefined if none match.
const firstBig = nums.find((n) => n > 10);Typorithm · easy
Step 1 of 8 · intro card
Array Methods
find returns the first element matching a predicate (or undefined); some and every return booleans for any-match and all-match; includes is a value check returning a boolean, and indexOf returns the value's position or -1. Predicate searches take a callback; value searches take a literal value.
Predicate searches take a callback. find returns the first matching element (or undefined); some returns true if any element matches; every returns true only if all elements match.
Value searches take a literal value instead of a callback. includes returns a boolean for whether the value is present; indexOf returns its position, or -1 if it is missing.
Choose by what you need back: an element (find), a yes/no (some, every, includes), or a position (indexOf).
find returns an element or undefined.
some and every return booleans (any vs all).
includes returns a boolean; indexOf returns an index or -1.
const nums = [3, 7, 12, 5, -2];
const firstBig = nums.find((n) => n > 10);
const hasNeg = nums.some((n) => n < 0);
const allPos = nums.every((n) => n > 0);
const has5 = nums.includes(5);
const where5 = nums.indexOf(5);Connect each part of the code to the concept before you type.
find runs a predicate and returns the first matching element, or undefined if none match.
const firstBig = nums.find((n) => n > 10);some returns true as soon as any element passes the predicate.
const hasNeg = nums.some((n) => n < 0);every returns true only when every element passes the predicate.
const allPos = nums.every((n) => n > 0);includes does a value check and returns true when the array contains that exact value.
const has5 = nums.includes(5);indexOf returns the position of the value, or -1 when it is absent.
const where5 = nums.indexOf(5);Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.