最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Opposite method of startsWith() in javascript - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Apr 21, 2020 at 8:42 Himanshu RanjanHimanshu Ranjan 1251 gold badge1 silver badge7 bronze badges 2
  • 2 !x.startsWith(y) – VLAZ Commented Apr 21, 2020 at 8:43
  • why not test logical NOT !? – Nina Scholz Commented Apr 21, 2020 at 8:43
Add a ment  | 

1 Answer 1

Reset to default 12

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
}
发布评论

评论列表(0)

  1. 暂无评论