JS Built-ins
Algorithmsbeginner

Check Element Exists

πŸ“– Usage Example
const arr = [10, 20, 30];
arr.includes(20); // true
arr.includes(99); // false

Array.includes() is a built-in linear search that returns a boolean.

Check Element Exists

This exercise focuses on checking if an element exists in an array without needing its index. This is useful when you only care about presence, not location.

function elementExists(arr: number[], target: number): boolean {
  // Return true if target exists in arr, false otherwise
}

elementExists([10, 20, 30], 20) // true
elementExists([10, 20, 30], 99) // false
πŸ’‘ Hints (3)
  • β€’ You can use the `includes()` method for simplicity.
  • β€’ Alternatively, use a loop with a boolean flag.
  • β€’ Compare each element with the target.