简体   繁体   English

javascript中startsWith()的相反方法

[英]Opposite method of startsWith() in javascript

I know what startsWith() does in js.我知道startsWith() 在js 中的作用。 Is there a method that checks opposite of what startsWith() does??有没有一种方法可以检查与startsWith()相反的方法? Something like "notstartsWith()".类似“notstartsWith()”的东西。 I want a method that would return false if a string starts with a pattern and true if it doesn't.我想要一个方法,如果字符串以模式开头,则返回 false,否则返回 true。

Use startsWith with the string you want to check against, then invert the check with !对要检查的字符串使用startsWith ,然后用!反转检查:

if (!str.startsWith('foo')) {
  // string does not start with foo
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM