JS Built-ins
← String134 / 195
StringString.prototype.startsWithintermediate

String.prototype.startsWith() β€” with position param

πŸ“– Usage Example
const str = 'Hello, World!'
str.startsWith('Hello')         // β†’ true
str.startsWith('World')         // β†’ false
str.startsWith('World', 7)      // β†’ true

Use startsWith() to check if a string begins with a specific prefix, with an optional start position.

String.prototype.startsWith() β€” Position Parameter

The optional second argument position specifies where to start the search.

Challenge: Implement startsAtPos(str, search, pos) that checks if str starts with search at position pos.

startsAtPos('hello world', 'world', 6) // β†’ true
startsAtPos('hello world', 'hello', 6) // β†’ false
πŸ’‘ Hints (1)
  • β€’ The second argument shifts the starting position of the search.