Skip to content
Advertisement

Convert string of numbers to array of numbers? [closed]

I have a string of numbers

let numbers = ["54321"]

I want to turn it into

let numbersToArray = [5,4,3,2,1]

I’ve tried split, push and other ways to but seem to crack it

Advertisement

Answer

let numbers = ["54321"]
const temp = numbers[0].split('')
const result = temp.map(n =>  parseInt(n))
console.log(result)
Advertisement