Es6-string-method-includes

提供:Dev Guides
2020年6月23日 (火) 08:04時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

ES6-新しい文字列メソッドinclude()

このメソッドは、文字列が指定された文字列の部分文字列かどうかを判断します。

構文

str.includes(searchString[, position])

パラメーター

  • searchString -検索するサブストリング。
  • 位置-searchStringの検索を開始するこの文字列内の位置。デフォルトは0です。

戻り値

文字列に部分文字列が含まれる場合、 true 。それ以外の場合は、 false

var str = 'Hello World';

console.log(str.includes('hell'))
console.log(str.includes('Hell'));

console.log(str.includes('or'));
console.log(str.includes('or',1))

出力

false
true
true
true