📜  数字拆分 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:22.001000             🧑  作者: Mango

代码示例1
const num = 1234567;
const strNum = String(num);

function getPartialString(str, len) {
  const result = [];
  for (let i = 0; i < strNum.length - (len - 1); ++i) {
    result.push(strNum.slice(i, i + len));
  }
  return result;
}
console.log(getPartialString(strNum, 3));
console.log(getPartialString(strNum, 4));
console.log(getPartialString(strNum, 5));