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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
split |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.