camelcase to snakecase javascript code example
Example 1: convert camelcase to sentence case javascript
var text = 'helloThereMister';
var result = text.replace( /([A-Z])/g, " $1" );
var finalResult = result.charAt(0).toUpperCase() + result.slice(1);
console.log(finalResult);
Example 2: how to convert snake case to camel snake case javascript typescript
function convertSnakeToCamelSnake(obj: any){
let newTokens = []
if (obj) {
Object.keys(obj).forEach( key => {
newTokens = []
let tokens = key.split('_')
tokens.forEach( token => { newTokens.push(capitalizeFirstLetter(token)) });
newTokens.join('')
});
}else{
console.log("Can not convert case of object:" + obj)
}
return newTokens
}