Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Symbol.matchAll Property

Improve Article
Save Article
Like Article
  • Last Updated : 10 Feb, 2023
Improve Article
Save Article
Like Article

The Symbol.matchAll property returns the regular expression that matches against a string. The String.prototype.matchAll() method calls this function. The syntax of the property is as follows:

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.

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"]

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


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!