Javascript - String includes() Method

The includes() method determines whether a string contains the characters of a specified string.

Description

The includes() method determines whether a string contains the characters of a specified string.

It returns true if the string contains the characters, and false if not.

The includes() method is case sensitive.

Syntax

string.includes(searchvalue,start)

Parameter Values

Parameter RequireDescription
searchvalue Required. The string to search for
start Optional. Default 0. At which position to start the search

Return

A Boolean. Returns true if the string contains the value, otherwise it returns false

Example

Check if a string includes "world":

Demo

//check where if the string includes the specified value.
var str = "Hello world this is a test.";
var n = str.includes("world");
console.log(n);//  w w w .j  a v  a  2 s.co  m
//Check if a string includes "world", starting the search at position 12:
//check where if the string includes the specified value.
str = "Hello world, welcome to the universe.";
n = str.includes("world", 12);
console.log(n);

Result