JavaScript String includes() method
- 上一页 fromCharCode()
- 下一页 indexOf()
- 返回上一层 Nimtarin JavaScript String
Definition and usage
If the string contains the specified string,includes()
The method will return true
。
Otherwise return false
。
includes()
Method distinguishes between uppercase and lowercase.
Instance
Example 1
Check if the string contains "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);
Example 2
From position 12:
let text = "Hello world, welcome to the universe."; let result = text.includes("world", 12);
Syntax
string.includes(searchvalue, start)
Parameters
Parameters | Description |
---|---|
searchvalue | Required. The string to be searched. |
start | Optional. Starting position. Default value is 0. |
Return value
Type | Description |
---|---|
Boolean value | If the string contains this value, then true , ru he wei false 。 |
Browser support
includes()
Shi ECMAScript6 (ES6) te xing.
All modern browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
kai da su | kai da su | kai da su | kai da su | kai da su |
Internet Explorer 11 (tai ko da sau version) kai da su zhi includes()
。
- 上一页 fromCharCode()
- 下一页 indexOf()
- 返回上一层 Nimtarin JavaScript String