Jan Drewniak
Jan Drewniak

Reputation: 1384

Javascript join with special characters?

Is it possible to do something like this with .join?

['Jim','Joe'].join(" • ")

desired output:

jim • joe

EDIT:

Based on Quentin's answer, this is possible with the unicode escape sequence like so:

['Jim','Joe'].join(' \u2022\ ')

Upvotes: 0

Views: 4233

Answers (1)

Quentin
Quentin

Reputation: 943591

Yes, and that is the code to do it, assuming that you then do something that causes the text to be treated as HTML.

• has no special meaning in JavaScript.

If you want a literal • in the output, then use a literal •.

alert(['Jim','Joe'].join(" • "))

(Or you could use a JavaScript unicode escape sequence).

Upvotes: 5

Related Questions