数据处理列子 输入1000,生成["1", ",", "0", "0", "0"]
function toJson (num) {
var a = (num + '').split('')
var all = []
a.map((item, index) => {
all.push(item)
})
if (all.length > 3) {
const num = Math.ceil((all.length - 3) / 3)
if (num) {
for (let i = 0; i < num; i++) {
all.splice(all.length - 3 - i - 3 * i, 0, ',')
}
} else {
all.splice(num, 0, ',')
}
}
console.log(all)
},
网友评论