Lodash _.snakeCase() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

Converts string to snake_case — words lowercased and separated by _. Part of Lodash String since 3.0.0 (stable — not deprecated).

Note: Ideal for DB columns, JSON keys, and Python-style names. Same word-splitting family as _.camelCase and _.kebabCase — only the join style differs.

Syntax

Call _.snakeCase. Start with this line.

Lodash
_.snakeCase([string=''])
CallWhat it does
_.snakeCase([string=''])Primary signature.
_.snakeCase(string)Transform or inspect a string.

Prefer import snakeCase from "lodash/snakeCase" when you want a smaller bundle.

Library declarations
Lodash
_.snakeCase([string=''])

Parameters

ParameterDescription
stringOptional. Input to convert; default ''

Return Value

Return ValueDescription
*New snake_case string

Lodash Examples

Example 1 — Official: Spaces

Title-style words become lowercase with underscores.

Lodash
_.snakeCase('Foo Bar');
// → 'foo_bar'
Try It Yourself

How It Works

  1. Split. Space separates Foo and Bar.
  2. Lower. Both words become lowercase.
  3. Join. Insert _ between words.
  4. Result. foo_bar.

Example 2 — Official: camelCase

Capital letters mark new words.

Lodash
_.snakeCase('fooBar');
// → 'foo_bar'
Try It Yourself

How It Works

  1. Boundary. B in Bar starts a new word.
  2. Words. foo + bar.
  3. Join. Underscore between them.
  4. Use. Map JS identifiers to DB columns.

Example 3 — Official: Punctuation

Hyphens and extra dashes are treated as separators.

Lodash
_.snakeCase('--FOO-BAR--');
// → 'foo_bar'
Try It Yourself

How It Works

  1. Strip noise. Leading/trailing - are separators.
  2. Words. FOO and BAR.
  3. Lower + join. → foo_bar.
  4. Normalize. Great for messy CSS-like labels.

Example 4 — Numbers Split Words

Digit runs often become their own word segment.

Lodash
_.snakeCase('foo2bar');
// → 'foo_2_bar'
Try It Yourself

How It Works

  1. Letters / digits. Transition at 2 splits words.
  2. Three parts. foo, 2, bar.
  3. Join. foo_2_bar.
  4. Expect. Version-like tokens may gain underscores.

Example 5 — vs kebabCase / camelCase

Same words; different join styles.

Lodash
var s = 'Foo Bar';

_.snakeCase(s);  // → 'foo_bar'
_.kebabCase(s);  // → 'foo-bar'
_.camelCase(s);  // → 'fooBar'
Try It Yourself

How It Works

  1. Same split. All three see words Foo / Bar.
  2. snake. Join with _.
  3. kebab. Join with -.
  4. camel. No separator; capitalize later words.

Browser & Runtime Support

_.snakeCase is a Lodash String helper since 3.0.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.0.0+

_.snakeCase()

Available in [email protected] full builds and the lodash/snakeCase modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 3.0+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.snakeCase Lodash 3.0.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import snakeCase from "lodash/snakeCase" for smaller bundles. Use it to normalize labels into snake_case for APIs and databases.

Frequently Asked Questions

_.snakeCase([string='']) converts a string to snake_case: words lowercased and joined with underscores. Official: _.snakeCase('Foo Bar') → 'foo_bar'.
No. JavaScript strings are immutable. It always returns a new string.
snake_case uses underscores; kebab-case uses hyphens. Word-splitting rules are the same family of case helpers.
Spaces, hyphens, underscores, camelCase transitions, and most non-alphanumeric characters. Numbers often form their own word (foo2bar → foo_2_bar).
Empty string returns ''. Non-strings are coerced the Lodash way (null/undefined → empty string result from default '').
Use import snakeCase from "lodash/snakeCase" or require("lodash/snakeCase") for tree-shaking. Full build: import _ from "lodash" then _.snakeCase.

Next: _.split()

Split a string into an array by separator and limit.

_.split() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful