Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的代码“010200345”
我想每前三位分开
请帮助解决这个问题
谢谢卡皮尔
从我的一个项目中:
String.prototype.chunk = function(n) { if(this.length > 0) { n = typeof n == 'undefined' ? 2 : n; return this.match(new RegExp('.{1,'+n+'}','g')); } else return []; };
然后你可以使用这样的东西:
var parts = String(num).chunk(3); // parts as array