将字符串两个字符,两个字符 用:分开

var str = "avdgftjhhihguttu";
var arr = [];
for (var i = 0; i < str.length / 2; i++) {
var idx = i * 2;
var s = str.substring(idx, idx + 2);
arr.push(s);
}
arr.join(":");
console.log(arr.join(":"));   =》new_file.html:30 av:dg:ft:jh:hi:hg:ut:tu

转载于:https://www.cnblogs.com/chuxinsyn/p/7903235.html

你可能感兴趣的:(将字符串两个字符,两个字符 用:分开)