how to convert string to snake case in javascript
const snakeCase = (string) => {
const toSnakeCase = (str = "") => {
const strArr = str.split(" ");
const snakeArr = strArr.reduce((acc, val) => {
return acc.concat(val.toLowerCase());
}, []);
return snakeArr.join("_");
};
const newText = toSnakeCase(string);
return newText
};