How to convert camelcase to snake case in Javascript? [closed]
Solution 1:
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
Solution 2:
You could do something like this:
function camelToUnderscore(key) {
var result = key.replace( /([A-Z])/g, " $1" );
return result.split(' ').join('_').toLowerCase();
}
console.log(camelToUnderscore('itemName'));