Languages
[Edit]
EN

JavaScript - String includes() method example

0 points
Created by:
Palpys
764
// ONLINE-RUNNER:browser;

const text = 'ABCDE';

console.log(text.includes('A')); // true
console.log(text.includes('X')); // false

console.log(text.includes('B'));    // true
console.log(text.includes('B', 2)); // false

console.log(text.includes('ABC')); // true
console.log(text.includes('XYZ')); // false

1. Documentation

Syntax

String includes(searchString)

String includes(searchString, position)

Parameters

searchString - a string to be searched for within the string,

position - the position within the string at which to begin searching for searchString (0 by default).

ResultThe method returns true if the searchString is found anywhere within the given string,  otherwise returns false.
DescriptionThis method lets you determine whether or not a string includes another string.

See also

  1. JavaScript - check if string includes a substring

  2. JavaScript - check if string includes a character

References

  1. String.prototype.includes() - JavaScript | MDN

Alternative titles

  1. JavaScript - String.includes() documentation with examples
  2. js - String includes() method documentation with examples
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - String (documentation)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join