Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to convert a string of numbers into an array javascript

const numStr = "123456";

const numArr = strNum.split('').map((item) => parseInt(item, 10))

//OUTPUT
[1, 2, 3, 4, 5, 6]

// === STEP BY STEP ===

const step1 = numStr.split('') 
// -> ['1', '2', '3', '4', '5', '6'] 

const step2 = step1.map((item) => parseInt(item))
// -> [1, 2, 3, 4, 5, 6] 
 
PREVIOUS NEXT
Tagged: #convert #string #numbers #array #javascript
ADD COMMENT
Topic
Name
7+8 =