Created
July 4, 2021 15:57
-
-
Save kharioki/5559c08f01096b728a8ac1333a9d4e43 to your computer and use it in GitHub Desktop.
remove underscores or hyphens and uppercase the first letter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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