Saturday, September 21, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Symbol matchAll Property

JavaScript Symbol matchAll Property

JavaScript Symbol matchAll property used to return the regular expression that matches against a string. JavaScript String matchAll() method calls this property.

Syntax:

regExp[Symbol.matchAll](str);

Parameter: It takes a string used to find matches of the regular expression against the string.

Return value: The Symbol.matchAll property returns an iterator that returns regular expression matches against the string.

Below examples illustrate the JavaScript Symbol matchAll Property:

Example 1:

JavaScript




function func() {
  
// Final Result store result of matchAll property
const result = /a/[Symbol.matchAll]("abcd");
  
// Iterate on all matched elements
console.log(Array.from(result, (x) => x[0]));
}
  
func();


Output:

["a"]

Example 2:

JavaScript




function func() {
  
// finalResult store result of matchAll property
const result = /[0-9]+/g[Symbol.matchAll]("06-03-2021");
  
// Iterate on all matched elements
console.log(Array.from(result, (x) => x[0]));
}
  
func();


Output:

["06","03","2021"]

Example 3:

JavaScript




function func() {
  
// finalResult store result of
// matchAll property
const result = /[0-9]+/g[Symbol.matchAll]
("India got freedom in 1947");
  
// Iterate on all matched elements
console.log(Array.from(result, (x) => x[0]));
}
  
func();


Output:

["1947"]

Supported Browsers: The browsers supported by Symbol matchAll property are listed below:

  • Google Chrome 51
  • Firefox 50
  • Edge 15
  • Opera
  • Apple Safari

We have a complete list of Javascript symbols’ properties and methods, to check those please go through the Javascript Symbol Complete Reference article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments