Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Symbol.split

BaselineWidely available

TheSymbol.split static data property represents thewell-known symbolSymbol.split. TheString.prototype.split() method looks up this symbol on its first argument for the method that splits a string at the indices that match the current object.

For more information, seeRegExp.prototype[Symbol.split]() andString.prototype.split().

Try it

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"

Value

The well-known symbolSymbol.split.

Property attributes ofSymbol.split
Writableno
Enumerableno
Configurableno

Examples

Custom reverse 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" ]

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp