📜  如何在字符串中分配char javascript代码示例

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

代码示例1
function replaceAt(str, index, newChar) {
    function replacer(origChar, strIndex) {
        if (strIndex === index)
            return newChar;
        else
            return origChar;
    }
    return str.replace(/./g, replacer);
}

let str = 'Hello World';
str = replaceAt(str, 1, 'u');
console.log(str); // Hullo World
 Run code snippet