ES6 - New String Method includes()



The method determines if a string is a substring of the given string.

Syntax

str.includes(searchString[, position])

Parameters

  • searchString − The substring to search for.

  • Position − The position in this string at which to begin searching for searchString; defaults to 0.

Return Value

true if the string contains the substring ; otherwise, false.

Example

var str = 'Hello World';  

console.log(str.includes('hell'))     
console.log(str.includes('Hell'));  

console.log(str.includes('or'));   
console.log(str.includes('or',1))

Output

false 
true 
true 
true 
Advertisements