LoginSignup
0
0

More than 1 year has passed since last update.

includesとは?

  • 〇〇が含まれているかどうか判断する時に使う

実践

まずはじめに以下の変数を定義します。

index.js
const color = '赤青'
const red = ''
const blue = ''
const white = ''

次に任意の文字が含まれているかどうかのロジックを作ります。(本題)

index.js
color.includes(red)
// true

color.includes(blue)
// true

color.includes(white)
// false

実際にアプリなどで使う場合の想定としては、その値が含まれているかどうかで条件分岐を行ったりする場面が想定されます。

0
0
0

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
0
0