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.

2

1 Answer

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 } 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy