I looked at some other questions, haven't found one specific to this issue. Here is what I have:
function toCamelCase(str){
  const _str = str.split(/-|_/)
  for (let i = 0; i < _str.length; i++) {
    // if first character of string is capital,
    // make it Pascal Case, not Camel Case
    if (i === 0) {
      _str[i][0] =
        _str[i][0].match(/[A-Z]/)
          ? _str[i][0].toUpperCase()
          : _str[i][0].toLowerCase()
    } else {
      _str[i][0] = _str[i][0].toUpperCase()
    }
  }
  return _str.join("")
}
toCamelCase("This-is_a_test-string") // Thisisateststring
The output should be ThisIsATestString, but for some reason it is not working. What's weird is that the first if (i === 0) .. enters and assigns properly, but the rest doesn't work, even though it is entered.