js 字符串按固定长度分割成数组 --吴中飞

直接上代码

function mySplit(str,leng){
let arr = [];

let index = 0;
while(index<str.length){
arr.push(str.slice(index,index +=leng));
}

console.log(arr);
}

mysplit('032390',2);// ['03','23','90']

总结:关键就是不停的根据步长改变下标

原文地址:https://www.cnblogs.com/ouyangfeifei/p/14045270.html