Symbol.matchAll

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

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

시도해보기

잘 알려진 심볼 @@matchAll.

Property attributes of Symbol.matchAll
Writable 불가능
Enumerable 불가능
Configurable 불가능

예제

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 Language Specification
# sec-symbol.matchall

브라우저 호환성

BCD tables only load in the browser

같이 보기