I have an array like this:
var array = ["ejemplo.com","otrositio.com","etcetera.net"];
And I want to display it in an textarea
as-is (with the brackets, commas, and quotes), that is, like this:
["ejemplo.com","otrositio.com","etcetera.net"]
In case it helps, I do it in order to create a custom code that users have to place, and in that code there must be an array, which is this.
I know how to add it to the textarea, for now I just need it to be stored in a normal variable like any string.
Just use
JSON.stringify( )
, which is there for just that: Convert aArray
or aObject
to a text string:The resulting string, additionally, is a valid JSON, which can be sent or stored as is.
Another option to the one provided by @Trauma is to use the string templates together with the join method :
Edit : @Trauma's is a better option, let's be clear.