JavaScript Array Formatter — Turn Any List into a JS Array Online

Every developer knows the chore: a list arrives — from a spreadsheet, an email, a spec doc — and you need it as a JavaScript array, quoted and comma’d, without spending ten minutes on find-and-replace. This JavaScript array formatter does it in one paste: one item per line or comma-separated, and out comes a clean array literal with your choice of quote style and layout.

Escaping is handled properly: if an item contains the quote character you picked, or a backslash, it is escaped so the array you paste into your code parses exactly as intended. Everything runs in your browser.

Why this tiny tool saves real time

Turning a raw list into an array literal by hand is error-prone in three specific places. Quotes: miss one and the file will not parse; put the wrong kind around a string that contains an apostrophe — dragon’s breath — and it breaks somewhere else entirely. Commas: the last item must not have one in older style guides and must have one in others (trailing commas keep diffs clean, which is why the option is here). Stray whitespace: items copied from spreadsheets carry trailing spaces and blank lines that silently become part of your data. The formatter trims every item, drops empty lines, escapes what needs escaping and counts the result, so what lands in your code is exactly the list you started with.

A worked example

Paste a shopping list, one item per line, choose one-per-line layout with single quotes, and:

['apple', 'banana', 'cherry', 'dragon fruit'] becomes a tidy vertical array ready for a config file. Tick the declaration option and it arrives as const items = [...] — no extra typing. If your source is a single comma-separated line instead (“red, green, blue”), the tool detects that and splits on commas just the same.

Which options when

Quotes. Match your project’s linter: single quotes are the common JavaScript default; double quotes if your data is full of apostrophes (fewer escapes to read). One per line suits long lists and anything under version control — one item changed, one diff line. Inline suits short lists in tight code. Trailing comma is safe in all modern engines and makes future edits painless. Declaration saves a step when the array is going straight into a new file.

Honest limits

This formatter produces an array of strings. If your list is numbers and you need them unquoted, that is a different conversion — pasting string numbers into code that expects numbers is a classic silent bug, so the tool does not pretend to guess. It also does not dedupe: repeated items are your data’s business, and silently dropping them could hide a problem in the source list. And like every tool on this page, it runs locally — paste internal option lists, feature flags or customer segment names without them leaving your machine.

Frequently asked questions

What if an item contains a comma?

Use one-item-per-line input: in line mode, commas inside an item are treated as part of the item. Comma-separated mode cannot tell a separator comma from a data comma — no tool can, without more information.

Does it handle quotes inside items?

Yes. An apostrophe inside a single-quoted item is escaped (it\'s), a double quote inside a double-quoted item likewise, and backslashes are doubled first so existing escapes survive the trip.

Can I make an array of numbers or booleans?

Not here — the output is deliberately always strings, because guessing types corrupts data (the string “007” is not the number 7). Format the strings here, then convert types explicitly in your code where you can see it happen.

Is my list uploaded?

No. It is split, quoted and joined in your browser tab.

Related tools

Versión en español: Formateador de Arrays JavaScript — Convierte una Lista en un Array JS Online. You may also like: SQL Query Pretty Printer — Format SQL Online, Free SQL Formatter · JSON Formatter.


Embed this tool on your website — free

Copy the code below to add this working tool to your own page. A small credit link stays with it — that’s all we ask.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top