let number = "10145"; //put number into array of arrays like 10145 becomes [ [ '1', '0' ], [ '1', '4', '5' ] ] let numArray = number.split(""); const chunkRight = (arr, size) => { const rm = arr.length % size; return rm ? [arr.slice(0, rm), ..._.chunk(arr.slice(rm), size)] : _.chunk(arr, size); }; const result = chunkRight(numArray, 3);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter