Saturday, October 25, 2025
HomeLanguagesJavascriptJavaScript Symbol split Property

JavaScript Symbol split Property

JavaScript Symbol split property is used to specify the method that splits a string at the indices that match a regular expression. This property is called by the String.split() method.

Syntax:

[Symbol.split](string)

Property attributes: It accepts a “String” which is not Writable, Enumerable, and Configurable.

Return value: It returns a string that is split from the given expression.

Below examples illustrate the Symbol split property in JavaScript:

Example 1: In this example, we will split the string and add (“”) in it.

Javascript




class Split1 {
    constructor(value) {
            this.value = value;
        }
        [Symbol.split](string) {
            const index = string.indexOf(this.value);
            return "'" + string.substr(0, index) + "' '" +
                this.value + "' '" + string.substr(index + this.value.length) + "'";
        }
}
  
console.log('neveropen'.split(new Split1('for')));
console.log('Geeks1Geeks2Geeks3Geeks4'.split(new Split1('Geeks')));


Output:

"'Geeks' 'for' 'Geeks'"
"'' 'Geeks' '1Geeks2Geeks3Geeks4'"

Example 2: In this example, we will split the string and add (_) in it.

Javascript




class Split1 {
    constructor(value) {
            this.value = value;
        }
        [Symbol.split](string) {
            const index = string.indexOf(this.value);
            return "_" + string.substr(0, index) + "__" +
                this.value + "__" + string.substr(index + this.value.length) + "_";
        }
}
  
console.log('neveropen'.split(new Split1('for')));
console.log('Computer Science Portal'.split(new Split1(' ')));


Output:

_Geeks__for__Geeks_
_Computer__ __Science Portal_

Supported Browsers: The browsers supported by JavaScript Symbol split property are listed below:

  • Google Chrome 51
  • Firefox 50
  • Edge 15
  • Opera
  • Apple Safari

We have a complete list of Javascript symbols’ properties and methods, to check those please go through the Javascript Symbol Complete Reference article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS