Convert kebab-case to camelCase with JavaScript

You can also try regex.

camelize = s => s.replace(/-./g, x=>x[1].toUpperCase())

const camelize = s => s.replace(/-./g, x=>x[1].toUpperCase())
const words = ["stack-overflow","camel-case","alllowercase","allcapitalletters","custom-xml-parser","api-finder","json-response-data","person20-address","user-api20-endpoint"];
console.log(words.map(camelize));

Looks only for hyphen followed by any character, and capitalises it and replaces the hyphen+character with the capitalised character.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)