search
LoginSignup
4

More than 5 years have passed since last update.

posted at

updated at

JavaScriptで、変数の値がどれかに一致すればtrueになる式の書き方

===||を使ったオーソドックスな書き方

const x = 'banana';
console.log(x === 'apple' || x === 'banana' || x === 'orange'); // => true

ES2016のArray.prototype.includes()を使った書き方

const x = 'banana';
console.log(['apple', 'banana', 'orange'].includes(x)); // => true

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
What you can do with signing up
4