JavaScript String includes() method

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");

Try it yourself

let text = "Hello World, welcome to the universe.";
let result = text.includes("world", 12);

Try it yourself

Example 2

From position 12:

let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);

Try it yourself

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()

相关页面

JavaScript ɗanar ɗanar

JavaScript ɗanar ɗanar

JavaScript ɗanar ɗanar