ES6 - RegExp split()



This method splits a string object on the basis of the separator specified and returns an array of strings.

Syntax

str.split([separator[, limit]])           

Parameter Details

  • separator − Optional. Specifies the separator character for the string.

  • limit − Optional. Specifies a limit on the number of splits to be found.

Return Value

Returns the index at which the match was found in the string.

Example

var names = 'Monday;Tuesday;Wednesday';  
console.log(names);  
var re = /\s*;\s*/; 
var nameList = names.split(re);  
console.log(nameList);

Output

Monday;Tuesday;Wednesday 
Monday,Tuesday,Wednesday   
Advertisements