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 September 2015.

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® 2025 Language Specification
# sec-symbol.split

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
split

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

같이 보기