JavaScript文字列includes()
例
文字列に「world」が含まれているかどうかを確認します。
let text = "Hello world, welcome to the universe.";
let result = text.includes("world");
let text = "Hello World, welcome to the universe.";
let result = text.includes("world", 12);
以下のその他の例。
定義と使用法
文字列に指定された文字列が含まれている場合、メソッドincludes()
は戻ります。true
それ以外の場合はを返しますfalse
。
このincludes()
方法では大文字と小文字が区別されます。
構文
string.includes(searchvalue, start)
パラメーター
Parameter | Description |
searchvalue | Required. The string to search for. |
start | Optional. The position to start from. Default value is 0. |
戻り値
タイプ | 説明 |
ブール値。 | true 文字列に値が含まれている場合、それ以外の場合はfalse 。 |
その他の例
位置12から開始します。
let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);
ブラウザのサポート
includes()
ECMAScript6(ES6)機能です。
ES6(JavaScript 2015)は、最新のすべてのブラウザーでサポートされています。
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
includes()
Internet Explorer 11(またはそれ以前)ではサポートされていません。