Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
Format your strings to Camel Case with Lodash
node v14.20.1
version:
1.0.0
endpoint
share
tweet
These examples show you how to format any string to camelCase using Lodash's `_.camelCase` function.
const _ = require("lodash");
It works out-of-the-box with dashes and underscores:
_.camelCase("my_string");
_.camelCase("another-string");
However, you may not have the desired result with weird casings in you string:
_.camelCase("mY-STrInG_iS-AwEsOmE");
To fix this, ensure to format your string to lower case **before** applying the `camelcase` function:
_.camelCase("mY-STrInG_iS-AwEsOmE".toLowerCase());
Note that the function works smoothly with dot notation (for example, flattened object keys):
_.camelCase("foo.bar");
Loading…
no comments
sign in
to comment