Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite method of startsWith() in javascript

Tags:

javascript

I know what startsWith() does in js. Is there a method that checks opposite of what startsWith() does?? Something like "notstartsWith()". I want a method that would return false if a string starts with a pattern and true if it doesn't.

like image 246
Himanshu Ranjan Avatar asked Jun 14 '26 15:06

Himanshu Ranjan


1 Answers

Use startsWith with the string you want to check against, then invert the check with !:

if (!str.startsWith('foo')) {
  // string does not start with foo
}
like image 120
Snow Avatar answered Jun 17 '26 06:06

Snow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!