JavaScript

String.prototype.includes()メソッド

 編集:2022.08.16 by T.A.

その String 中に指定文字列が含まれているかを返します。

boolean=String.includes(searchString[, position] )
String String、文字列。
searchString str 内で検索される文字列。
position 文字列内で searchString を検索し始める位置。既定値は 0 です。
戻り値

boolean。文字列が検索値を含む場合、true。含まなければ、false。

解説

このメソッドによってある文字列内に別の文字列を含んでいるかどうか判断できます。

大文字・小文字の区別

includes() メソッドは大文字と小文字が区別します。例えば、次のコードでは false を返します:

'Blue Whale'.includes('blue')  // returns false
const str = 'To be, or not to be, that is the question.';

D=str.includes('To be');        //=true
D=str.includes('question');     //=true
D=str.includes('nonexistent');  //=false
D=str.includes('To be', 1);     //=false
D=str.includes('TO BE');        //=false
D=str.includes('');             //=true

テスト