split string and push into array javascript code example

Example 1: javascript split string into array by comma and space

input.split(/[ ,]+/); //splits string using RegEx on a space OR a comma

Example 2: 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 3: how to split a string in javascript

strName.split(); // My code