Skip to content

Split a number into an array of digits in JavaScript

Find out how to split a number into an array of digits in JavaScript.

Advertisements
function splitToDigits(n){
  return (n + '').split('').map((i) => { return Number(i); })
}

console.log(splitToDigits(12345)) //[1,2,3,4,5]
See also  Top K Frequent Words - Leetcode Challenge - Python Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.