split array js code example
Example 1: string split javascript
var myString = "An,array,in,a,string,separated,by,a,comma";
var myArray = myString.split(",");
Example 2: javascript split
var arr = foo.split('');
console.log(arr);
Example 3: javascript slice string from character
var input = 'john smith~123 Street~Apt 4~New York~NY~12345';
var fields = input.split('~');
var name = fields[0];
var street = fields[1];
Example 4: split array javascript
arr.slice(start, end);
Example 5: split javascript
var str = "12,15,16,78,59";
var res = str.split(",");
console.log(res[0]);
console.log(res[2]);
Example 6: javascript split
var names = 'Harry ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ';
console.log(names);
var re = /\s*(?:;|$)\s*/;
var nameList = names.split(re);
console.log(nameList);