Here's my function. It's supposed to return backgroundColor
instead of backgroundcolor
.
What's my problem?
function camelize(str) {
let newStr = str.split('-');
newStr.forEach((item, index) => {
if (index > 0) {
item.toLowerCase();
item = item[0].toUpperCase() + item.slice(1);
}
});
newStr = newStr.join('');
return newStr;
}
console.log(camelize("background-color")); //'backgroundсolor' instead of 'backgroundColor'