在字符串指定位置插入一个字符

function newStr(str, n) {
var newStr = str.slice(0, str.length - n) + ‘.’ + str.slice(-n)
return newStr
}
console.log(newStr(‘12111111115’, 2)) // 121111111.15

你可能感兴趣的:(字符串)