Skip to content

Lines to a JavaScript array

Turn one item per line into a ready-to-paste JavaScript array literal.

  1. 1.Text to array converter

Paste a list with one item on each line and get back a JavaScript array declaration you can drop straight into a file. Each line becomes a double-quoted string, the whole thing is indented one item per line, and the declaration is named for you — blank lines and stray leading or trailing spaces are dropped on the way in, because a list copied out of a spreadsheet or a chat message almost always carries them.

This is the same tool as the text to array converter with the delimiter fixed to a line break, so if you need single quotes, a different variable name, a compact one-line array or the numbers left unquoted, open it on its own page and every option is there. Nothing is uploaded — the conversion happens in your browser.

Questions

What happens to blank lines?
They are removed. An empty line is not an item, so it never becomes an empty string in the array.
Can I change the variable name?
Yes, on the text to array converter page. This recipe uses the default name so the output is predictable.
Are spaces around each item kept?
No. Each line is trimmed before it is quoted, so a trailing space in your paste does not end up inside the string.

Build your own chain in the pipeline builder.