DEV Community

Cover image for Javascript | String Methods

Javascript | String Methods

Shubham Tiwari on March 07, 2024

Hello my beginner frontend developers, today i will be showing Javascript string methods in 2 different categories - Important and rarely used. Le...
Collapse
 
lionelrowe profile image
lionel-rowe • Edited
// 2. search - true - search for the passed string and returns boolean
const stringSearch = str.search("World");

No, it searches for the passed regex and returns a number (the index of the match). If a string is passed, it's coerced to a regex before searching.

'abc.'.search('.') // 0
'$abc'.search('$') // 4
'[abc'.search('[') // throws Uncaught SyntaxError: Invalid regular expression
Enter fullscreen mode Exit fullscreen mode
Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

Yeah true, thanks for covering these cases

Collapse
 
nomanabid2016 profile image
Noman Abid

Please correct your 5th point

Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

Thanks for the correction bro 🫡