How to useJavaScript String includes() Method in Javascript
JavaScript String includes() method determines whether a string contains the given characters within it or not. This method returns true if the string contains the characters, otherwise, it returns false.
Syntax:
string.includes(searchvalue, start);
Example: This example illustrates matching a single character with Multiple possibilities using the includes() Method.
// Create a input string
let string = "w3wiki";
// The letters to be matched
const character = "aeiou";
// To store the letters found
result = [];
// Split character string and iterate
character.split("").some((char) => {
// Check if character is present
if (string.includes(char))
// Store the characters
result.push(char);
});
// Display the result
console.log(result);
Output
[ 'e', 'o' ]
JavaScript Program to Match Single Character with Multiple Possibilities
In this article, we will write programs to check all possible matching in JavaScript. We will check the occurrence of characters individually in the given string or sequence. In this article, we will check the occurrence of vowels in the given string.
Table of Content
- Using JavaScript RegExp test() Method
- Using JavaScript String match() Method
- Using JavaScript String includes() Method
- Using JavaScript String indexOf() Method
- Using Array.some()