Technical skill practice

JavaScript Array join: Build Text and Preserve Empty Positions

join turns array elements into one string with a separator between positions. It does not combine arrays into another array. Empty-like entries can leave separators without visible text, so inspect the intended field positions.

The task

Build a location label, then compare a missing slot with explicit null and undefined entries. Decide whether those blank-looking positions should be allowed before using the output as a report.

Runnable Node 22 example

const assert = require('node:assert/strict');

assert.equal(['north', 'aisle', '4'].join(' / '), 'north / aisle / 4');
assert.equal([].join('|'), '');
assert.equal(['A', undefined, null, 'D'].join('|'), 'A|||D');
assert.equal(['A', , 'C'].join('|'), 'A||C');
assert.equal(['A', 'B'].join(), 'A,B');
console.log(['north', 'aisle', '4'].join(' / '));
console.log(['A', undefined, null, 'D'].join('|'));

Expected output and explanation

The normal label places the chosen separator between three values. In the second printed line, undefined and null contribute empty text, leaving three separators around four positions. The sparse-array assertion demonstrates a similar-looking gap from an absent element.

The empty list produces an empty string, and an omitted separator uses a comma. Those results may be appropriate for display but do not preserve every distinction in the source values. A consumer cannot infer whether the original blank position was null, undefined or absent from the joined text alone.

Output from the example

north / aisle / 4

A|||D

Pitfall to check

join is not automatic escaping for delimiter-separated data. If an element can contain the separator, define quoting or another encoding scheme instead of assuming the result can always be split back without loss.

Questions, answered

Does join change the source array?

No. It produces text. Mutating the source afterward is a separate operation and does not retroactively edit a string already produced.

Sources and examples

ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.

Your experience. A complete resume.

Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.

Free account required. Free-plan PDF exports include a watermark.