javascript,每长度拆分字符串

时间:2014-12-11 02:43:05

标签: javascript html string

我将数字更改为字符串

ex) 

721,011 => seven hundred twenty-one thousand eleven

21,011 => twenty-one thousand eleven

我发现每三个字分开

https://gist.github.com/hendriklammers/5231994

但它在第一个单词

分裂
 721,011 => [721, 011] (It is perfect)
 21,011 => [210, 11] (It is not perfect, wanna [21, 011])
 2123011 => [212, 301, 1] (It is not perfect, wanna [2, 123, 011])
 21230ef11 => [212, 301, 1] (It is not perfect, I'll accept only integer , wanna [2, 123, 011]), (using fucntion num.toString().replace(/\D/g, "") )

如何按长度分割字符串?

它只是反向字符串并重新反转吗?

1 个答案:

答案 0 :(得分:1)

如果我不明白你的问题完全错了,那就简单了

var a = '21,011'
var b = a.split(',');

应该做的。