Last active
August 27, 2019 13:53
-
-
Save doesdev/861111e6ab00030cedf65f59287f9d8a to your computer and use it in GitHub Desktop.
Split Array into Arrays of X length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let srcAry = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] | |
let splitBy = 3 | |
let split = [] | |
srcAry.forEach((val, i) => { | |
let ary = i % splitBy ? split[split.length - 1] : (split[split.length] = []) | |
ary.push(val) | |
}) | |
console.log(split) |
Author
doesdev
commented
Aug 27, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment