Symbol.split JavaScript

The JavaScript Symbol.split property splits a part of the string from the indices that match the specified regular expression.

Syntax:

Symbol.split(string) 

Parameters:
string: It represents the string.

Returns:
It returns a string that is split from the specified expression.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>
class obj {
constructor(a) {
this.a = a; }
[Symbol.split](string)
{ var index = string.indexOf(this.a);
return this.a; } }
document.write('HELLO WORLD!'.split(new obj('WORLD')));
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>
class SplitTest {
constructor(value) {
this.value = value;
}
[Symbol.split](string) {
var index = string.indexOf(this.value);
return this.value + string.substr(0, index) + "/"
+ string.substr(index + this.value.length);
}
}
document.write('w3spoint'.split(new SplitTest('java')));
</script>
</body>
</html>