JS Built-ins
← Array105 / 226
ArrayArray.prototype.includesintermediate

Array.prototype.includes() β€” search from index

πŸ“– Usage Example
const arr = [1, 2, 3, 1, 2]
arr.includes(1, 2)  // β†’ true  (starts searching at index 2)

Pass a second argument to includes() to start the search from a specific index.

Array.prototype.includes() β€” fromIndex

The optional second argument fromIndex specifies where to start searching. This allows you to skip earlier occurrences.

Challenge: Implement hasAfter(arr, val, from) that uses arr.includes(val, from) to check for val starting at index from.

hasAfter([1, 2, 3, 2, 1], 2, 2) // β†’ true  (found at index 3)
hasAfter([1, 2, 3, 2, 1], 2, 4) // β†’ false (no 2 at index >= 4)
πŸ’‘ Hints (2)
  • β€’ `includes(val, from)` starts searching at index `from` and goes to the end.
  • β€’ Elements before `from` are ignored even if they match.