Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created July 4, 2021 15:57
Show Gist options
  • Save kharioki/5559c08f01096b728a8ac1333a9d4e43 to your computer and use it in GitHub Desktop.
Save kharioki/5559c08f01096b728a8ac1333a9d4e43 to your computer and use it in GitHub Desktop.
remove underscores or hyphens and uppercase the first letter
const str = "Yeah_so_many_underscores here";
// const str = "A-B-C";
// const newStr = str.replace(/_/g, " ");
const newStr = str.replace(/[_!@#$%^&*, -]/g, " ");
const arr = newStr.split(' ');
// remove first word
let arr1 = arr.slice(0,1)
let arr2 = arr.slice(1)
let newArr = [];
const x = arr2.map(word => word.charAt(0).toUpperCase() + word.slice(1))
newArr = [...arr1, ...x]
newArr= newArr.join().replace(/,/g, '');
console.log(newArr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment