I've number i.e. 12345678 and I want to change it to the following format [12,34,56,78]. How can I do that?
Asked
Active
Viewed 84 times
-3
-
4please make an attempt and share it before asking for help – depperm Oct 31 '19 at 12:33
-
Can you show us something you have tried already (some code)? – Rojo Oct 31 '19 at 12:33
1 Answers
4
You can use match
var str = '12345678';
console.log(str.match(/.{1,2}/g).map(Number));

Pushprajsinh Chudasama
- 7,772
- 4
- 20
- 43