javascript split string to array code example
Example 1: javascript split array into chuncks of
function splitArrayIntoChunksOfLen(arr, len) {
var chunks = [], i = 0, n = arr.length;
while (i < n) {
chunks.push(arr.slice(i, i += len));
}
return chunks;
}
var alphabet=['a','b','c','d','e','f'];
var alphabetPairs=splitArrayIntoChunksOfLen(alphabet,2);
Example 2: javascript explode
var str = "Well, how, are , we , doing, today";
var res = str.split(",");
Example 3: string to array javascript
const str = 'Hello!';
console.log(Array.from(str));
Example 4: javascript split
var arr = foo.split('');
console.log(arr);
Example 5: js string to array
var myString = 'no,u';
var MyArray = myString.split(',');
Example 6: javascript turn string into array
var fruits = 'apple, orange, pear, banana, raspberry, peach';
var ar = fruits.split(', ');
console.log( ar );