String.prototype.searchbeginner'hello world'.search(/world/) // β 6
'hello'.search(/d/) // β -1
'abc123'.search(/[0-9]/) // β 3Use search() to find the index of the first regex match in a string, returning -1 if not found.
Both return the index of a match or -1. search accepts regex; indexOf accepts only strings.
Challenge: Implement firstLetterIndex(str) that returns the index of the first letter using search.
firstLetterIndex('123abc') // β 3
firstLetterIndex('hello') // β 0