→
その String 中に指定文字列が含まれているかを返します。
String | String、文字列。 |
---|---|
searchString | str 内で検索される文字列。 |
position | 文字列内で searchString を検索し始める位置。既定値は 0 です。 |
このメソッドによってある文字列内に別の文字列を含んでいるかどうか判断できます。
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