在字符串中循环并在函数和es6中添加一些没有构建的字符

Zr *_*sic -4 javascript arrays loops for-loop while-loop

如何循环"字符串"并通过旧式技术在没有内置函数和es6的情况下在它们之间添加一些字符

the input: "446697"
output: "44669-7" 
Run Code Online (Sandbox Code Playgroud)

添加dashbewtwen odd数字


小智 5

var input = '446697';
for(i=0;i<input.length;i=i+2){
    if(parseInt(input[i]) % 2 !== 0 && parseInt(input[i+1]) % 2 !== 0){
        input.slice(0, i) + '-' + input.slice(i);
    }
}
Run Code Online (Sandbox Code Playgroud)

您也可以使用子字符串而不是切片