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.split

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.split 정적 데이터 속성은 잘 알려진 심볼 @@split을 나타냅니다. String.prototype.split() 메서드는 현재 객체와 일치하는 인덱스에서 문자열을 분할하는 메서드의 첫 번째 인수에서 이 심볼을 찾습니다.

보다 상세한 내용은 RegExp.prototype[@@split]()String.prototype.split()를 참조하시기 바랍니다.

시도해 보기

class Split1 {
  constructor(value) {
    this.value = value;
  }
  [Symbol.split](string) {
    const index = string.indexOf(this.value);
    return `${this.value}${string.substring(0, index)}/${string.substring(
      index + this.value.length,
    )}`;
  }
}

console.log("foobar".split(new Split1("foo")));
// Expected output: "foo/bar"

잘 알려진 심볼 @@split.

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

예제

사용자 정의 역분할

js
class ReverseSplit {
  [Symbol.split](string) {
    const array = string.split(" ");
    return array.reverse();
  }
}

console.log("Another one bites the dust".split(new ReverseSplit()));
// [ "dust", "the", "bites", "one", "Another" ]

명세서

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

브라우저 호환성

같이 보기