contains()
String.contains()は文字列に引数で指定した文字列が含まれるか判定するメソッドです。
文字列が引数に指定した文字列を含む場合はtrueを、含まない場合はfalseを返します。
"1234".contains("23");//true
"1234".contains("24");//false
第2引数には文字列の測定の開始位置を指定することができます。
"1234".contains("23",2);//false
"1234".contains("34",2);//true
この場合は3文字目の3から測定を開始します。(1文字目は0)
String.contains()はECMAScript6で策定されており、Firefoxなどのブラウザで先行実装がされています。
登録日 : 2013年07月26日 最終更新日 : 2013年7月26日
同じカテゴリー(String)のエントリー
- valueOf()
- toUpperCase()
- toString()
- toLowerCase()
- toLocaleUpperCase()
- toLocaleLowerCase()
- substring()
- substr()
- split()
- slice()
- search()
- replace()
- match()
- contains()
- endsWith()
- startsWith()
- localeCompare()
- lastIndexOf()
- indexOf()
- fromCharCode()
- concat()
- charCodeAt()
- charAt()
- trimLeft()
- trimRight()
- trim()
- length