camel to snake case javascript code example
Example 1: js camel case to snake case
var s1 = 'someTextHere';
var o1 = s1.split(/(?=[A-Z])/).join('_').toLowerCase();
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
}