Skip to content

Home

Digitize number

Converts a number to an array of digits, removing its sign if necessary.

const digitize = n => [...`${Math.abs(n)}`].map(i => parseInt(i));

digitize(123); // [1, 2, 3]
digitize(-123); // [1, 2, 3]

More like this

Start typing a keyphrase to see matching snippets.