JS Built-ins
StringString.prototype.matchbeginner

String.prototype.match() β€” no match returns null

πŸ“– Usage Example
'test 123 foo'.match(/d+/)    // β†’ ['123', index: 5, ...]
'test 1 and 2'.match(/d+/g)  // β†’ ['1', '2']

Use match() to search a string against a regex and return the match results, or null if not found.

String.prototype.match() β€” Null Return

When the regex does not match, .match() returns null.

Challenge: Implement hasMatch(str, pattern) that returns true when the pattern is found.

hasMatch('hello123', /\d+/) // β†’ true
hasMatch('hello', /\d+/)    // β†’ false
πŸ’‘ Hints (1)
  • β€’ `.match()` returns `null` when there is no match.