how to split 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 how to split array into subarrays javascript
// Example array.
let randomArray = [3, 5, 1, 5, 7,];
// Create an empty array.
let arrayOfArrays = [];
function splitArray( array ) {
while (array.length > 0) {
let arrayElement = array.splice(0,1);
arrayOfArrays.push(arrayElement);
}
return arrayOfArrays;
}
// Call the function while passing in an array of your choice.
splitArray(randomArray)
// => [ [ 3 ], [ 5 ], [ 1 ], [ 5 ], [ 7 ] ]
Example 3: HOW TO SPLIT AN ARRAY JAVASCRIPT
array.splice(index, number, item1, ....., itemN)