JS Built-ins
StringString.prototype.indexOfbeginner

String.prototype.indexOf() β€” not found returns -1

πŸ“– Usage Example
const str = 'hello world'
str.indexOf('world')    // β†’ 6
str.indexOf('xyz')      // β†’ -1
str.indexOf('l')        // β†’ 2

Use indexOf() to find the index of the first occurrence of a substring, returning -1 if not found.

String.prototype.indexOf() β€” Not Found

Challenge: Implement contains(str, sub) that returns true when sub is found (i.e. indexOf !== -1).

contains('hello', 'ell') // β†’ true
contains('hello', 'xyz') // β†’ false
πŸ’‘ Hints (1)
  • β€’ `indexOf() !== -1` is the classic pre-ES6 way to check if a substring exists.