Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  48] [ 1]  / answers: 1 / hits: 88530  / 5 Years ago, fri, january 18, 2019, 12:00:00

I want to convert a string of that is in camel case to snake case using TypeScript.


Remember that the "snake case" refers to the format style in which each space is replaced by an underscore (_) character and the first letter of each word written in lowercase.


Example: fieldName to field_name should be a valid conversion, but FieldName to Field_Name is not valid.


More From » json

 Answers
21
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);

[#52757] Friday, January 11, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freddiem

Total Points: 456
Total Questions: 116
Total Answers: 101

Location: Dominica
Member since Mon, Jan 4, 2021
3 Years ago
;