I am trying to capitalize a character within a string in javascript, my codes are :
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
    var str = "string";
    for(m = 0; m < str.length; m++){
    if(str[m] == "r"){
      str[m+1] = str[m+1].toUpperCase();
    }
    }
    alert(str);
}
</script>
So what I am trying to do is, if the character is r,capitalize the next character. But is not woking means its the same string alerting.
 
     
     
     
     
    