LoginSignup
17
15

More than 5 years have passed since last update.

javascriptで文字列内に任意の文字列が含まれているかをtrue/falseで返す

Last updated at Posted at 2015-07-23

よく忘れるのでメモ。

'検索される文字列'.indexOf('検索') != -1

indexOfはtrue/falseを返さない。

一致した文字列が何文字目から始まるかを返す。検索文字列が存在しなかった場合は-1を返す。

> '検索される文字列'.indexOf('検索') != -1
> true
> '検索される文字列'.indexOf('あ') != -1
> false
17
15
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
15