splitting an array code example

Example 1: 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 2: split array javascript

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

Example 3: HOW TO SPLIT AN ARRAY JAVASCRIPT

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

Example 4: how to slip array

import numpy as np # import some stuffs

arr = np.array([1, 2, 3, 4, 5, 6]) #create array


newarr = np.array_split(arr,3); # split the array up to 3
print(newarr)