0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【JavaScript】のincludesメソッドの使用方法

Posted at

includesメソッドとは

配列や文字列に特定の要素や文字列が含まれているかどうかを確認するために使用します。このメソッドは、要素が存在する場合にtrueを、存在しない場合にfalseを返します。

基本的な使い方

配列に対するincludesメソッド

javascript
const fruits = ['apple', 'banana', 'cherry'];

console.log(fruits.includes('banana')); // true
console.log(fruits.includes('grape'));  // false

文字列に対するincludesメソッド

javascript
const sentence = 'JavaScript includes method';

console.log(sentence.includes('includes')); // true
console.log(sentence.includes('method'));   // true
console.log(sentence.includes('Methods'));  // 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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?