Horje
What is includes() Method in JavaScript ?

In JavaScript, the includes() method is used to determine whether a string contains another string or a specified value. It returns true if the string contains the specified value, and false otherwise.

Syntax:

string.includes(searchValue, startIndex)
  • string: The string in which to search for the specified value.
  • searchValue: The value to search for within the string.
  • startIndex (optional): The index at which to start the search within the string. Default is 0.

Example: Here, the includes() method is called on the str string to determine whether it contains the substring “World”. Since “World” is present within the string, the method returns true, which is then assigned to the variable containsWorld.

Javascript

const str = "Hello, World!";
const containsWorld = str.includes("World");
 
console.log(containsWorld); // Output: true

Output

true




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is endsWith() Method in JavaScript ? What is endsWith() Method in JavaScript ?
What is anchor() Method in JavaScript ? What is anchor() Method in JavaScript ?
What is valueOf() Method in JavaScript ? What is valueOf() Method in JavaScript ?
What is startsWith() Method in JavaScript ? What is startsWith() Method in JavaScript ?
What is match() Method in JavaScript ? What is match() Method in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
11