This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Symbol.matchAll

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2020년 1월⁩.

Symbol.matchAll 정적 데이터 속성은 잘 알려진 심볼 @@matchAll을 나타냅니다. String.prototype.matchAll() 메서드는 문자열과 현재 객체의 일치 항목을 산출하는 반복자를 반환하는 메서드의 첫 번째 인수에서 이 심볼을 조회합니다.

더 많은 정보를 참고하시려면 RegExp.prototype[@@matchAll]()String.prototype.matchAll()를 참고하시기 바랍니다.

시도해 보기

const re = /[0-9]+/g;
const str = "2016-01-02|2019-03-07";
const result = re[Symbol.matchAll](str);

console.log(Array.from(result, (x) => x[0]));
// Expected output: Array ["2016", "01", "02", "2019", "03", "07"]

잘 알려진 심볼 @@matchAll.

Property attributes of Symbol.matchAll
쓰기 가능불가능
열거 가능불가능
설정 가능불가능

예제

Symbol.matchAll 사용하기

js
const str = "2016-01-02|2019-03-07";

const numbers = {
  *[Symbol.matchAll](str) {
    for (const n of str.matchAll(/[0-9]+/g)) yield n[0];
  },
};

console.log(Array.from(str.matchAll(numbers)));
// ["2016", "01", "02", "2019", "03", "07"]

명세서

Specification
ECMAScript® 2026 Language Specification
# sec-symbol.matchall

브라우저 호환성

같이 보기