0

says I have a long list of item

a
b
c

I want to quickly split them into array, I did

"a
b
c".split('\n')

but I got Uncaught SyntaxError: Invalid or unexpected token

what's the problem?

akibo
  • 625
  • 11
  • 22

2 Answers2

5

Use backtick instead

`a
b
c`.split('\n')

Output

[
  "a",
  "b",
  "c"
]
Mario
  • 4,784
  • 3
  • 34
  • 50
-1

The code below is my best take, without using the \n operator (there is a much easier way to do a line break in JS) in JavaScript, using a little HTML, using the HTML line break operator. This is my code:

var list = ["a", "b", "c"];
var lineBreak = "<br/>";
document.write(list[0]+lineBreak+list[1]+lineBreak+list[2]);

Is that good enough? Let me know.

anonsaicoder9
  • 107
  • 1
  • 12