How do I replace a character at a particular index in JavaScript?

后端 未结 24 2087
孤城傲影
孤城傲影 2020-11-21 07:23

I have a string, let\'s say Hello world and I need to replace the char at index 3. How can I replace a char by specifying a index?

var str = \"h         


        
24条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 08:13

    The methods on here are complicated. I would do it this way:

    var myString = "this is my string";
    myString = myString.replace(myString.charAt(number goes here), "insert replacement here");
    

    This is as simple as it gets.

提交回复
热议问题