To uppercase string index and replace it with current string index

I want a string (str) to get removed by the dashes and uppercase the char after where the dash has been removed.
The code removes the dashes successfully but don’t uppercase the next char.
I think the problem is at the line where I commented This code doesn’t work

So the variable str should get returned like: thisIsAnExample

str="this-is-an-example"

function toCamelCase(str) {
  if(str.includes("-")) {
    for(var i = 0; i < str.length; i++) {
      if (str[i] == "-") {
        str = str.replace(str[i], '');
        if (i < str.length-1) {
          str[i+1] = str[i+1].toUpperCase(); /*This code doesn't work*/
        }
      }
    }
  }
  return str;
}