For example suppose I always have a string that is delimited by \"-\". Is there a way to transform
it-is-a-great-day-today
to
itIsAGreatDayToday
This should also work:
function camelCase(str) {
return str.replace(/^.|-./g, function(letter, index) {
return index == 0 ? letter.toLowerCase() : letter.substr(1).toUpperCase();
});
}
And IMHO it is little bit more efficient since we're not converting whole input string to lowercase first and then convert to uppercase if needed. This function only converts first letter to lowercase and then every character after hyphen -
to uppercase.