split a string into an array javascript code example

Example 1: javascript explode

//split into array of strings.
var str = "Well, how, are , we , doing, today";
var res = str.split(",");

Example 2: javascript split

// bad example https://stackoverflow.com/questions/6484670/how-do-i-split-a-string-into-an-array-of-characters/38901550#38901550

var arr = foo.split(''); 
console.log(arr); // ["s", "o", "m", "e", "s", "t", "r", "i", "n", "g"]

Example 3: split array javascript

// Returns new array from exising one
arr.slice(start, end);

Example 4: HOW TO SPLIT AN ARRAY JAVASCRIPT

array.splice(index, number, item1, ....., itemN)

Tags: