Lodash _.join() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.join(array, [separator=',']) turns a collection into one string with a delimiter between each element’s text form.
  • Why null and undefined slots render as empty pieces (and how that differs from stringifying objects yourself).
  • When native Array.prototype.join is enough and when Lodash’s import still helps for consistency with other array utilities.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Optional prior read _.intersectionWith(); you should know that Array.prototype.join inserts the separator between every pair of adjacent elements, including when some slots stringify to empty text.

  • You are comfortable with template literals or string concatenation for building messages in JavaScript.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.join is the string bridge from list data: turn numbers, labels, or mixed cells into a single line for logs, URLs, or quick-and-dirty CSV previews. It mirrors the native join contract while living next to other Lodash array helpers in your imports.

Delimiter control

Default comma, or pass any string (even multi-character) between rendered elements.

Empty slots

null and undefined become empty segments, not the words “null” or “undefined.”

Read-only

The array is not modified; you only receive a new primitive string.

Syntax

javascript
_.join(array, [separator=','])
  • array: collection whose elements are stringified (array-like values are supported).
  • separator: optional glue between elements; defaults to a comma when omitted.
  • Returns: a single string; an empty array yields "".
1

Default comma

Omit the separator (or pass undefined) to get the familiar comma-separated line.

javascript
import join from "lodash/join";

join(["a", "b", "c"]);
// "a,b,c"
Try it Yourself
2

Custom separator

Use any string: pipe, newline, or a multi-character delimiter.

javascript
import join from "lodash/join";

join([1, 2, 3], " | ");
// "1 | 2 | 3"
Try it Yourself
3

null, undefined, and objects

Missing values collapse to empty segments; plain objects stringify to [object Object] unless you format them first.

javascript
import join from "lodash/join";

join(["x", null, undefined, 1, { id: 1 }], "-");
// "x---1-[object Object]"
Try it Yourself

📋 _.join vs Array.prototype.join

APINote
_.join(array, sep)Lodash import; works with array-like values after internal coercion.
array.join(sep)Built-in on real arrays; same separator and empty-slot rules for dense arrays.

Pitfalls to avoid

Obj

Objects do not JSON.stringify

Expect [object Object] unless you map rows with JSON.stringify, custom serializers, or dedicated CSV tooling.

Sep

Separator is not escaped

If a cell already contains your delimiter, readers cannot split the string reliably; escape or quote fields first.

Num

Numbers become text

Joined output is always a string; convert back with split and Number if you need numeric arrays again.

❓ FAQ

No. It only reads elements and returns a new string; the source collection is unchanged.
When you omit the second argument or pass undefined, Lodash uses a comma, matching the usual Array.prototype.join default.
They become empty string segments, so consecutive commas can appear when those slots sit next to each other.
For ordinary arrays the result matches join with the same separator. Lodash also accepts array-like values after coercion to a dense slice for joining.
Use import join from "lodash/join" or require("lodash/join") for tree-shaking friendly bundles.

Summary

  • Purpose: _.join(array, separator) builds one string from array elements with the given delimiter (comma by default).
  • Slots: null and undefined become empty string pieces between separators.
  • Next: Lodash _.last(), _.intersectionWith() (earlier in this track), or the array methods hub.
Did you know?

For CSV-style output with quoting rules, build rows explicitly or use a dedicated CSV library; _.join only inserts the separator between String(element) values (with empty slots for null / undefined).

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.

6 people found this page helpful