Categories
JavaScript Answers

How to separate an integer into separate digits in an array in JavaScript?

Spread the love

To separate an integer into separate digits in an array in JavaScript, we use the split method.

For instance, we write

const n = 123456789;
const digits = n.toString().split("");

to call toString to convert n to a string.

Then we call split to split the string into the individual digit strings.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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