Search code examples
javascriptjqueryhtmljsonjquery-tageditor

Trying to put every number/value in an object into a string array


I am creating my own JSON object which has info from a table and I am trying to JSON.stringify it so I can throw it into the "jQuery tagEditor's initialTags (the tag plugin StackOverflow uses").

Basically the object comes out like this:
[5094,5651,5812] - after I JSON.Stringify it

and it seems that the tagEditor() uses a string array that comes out like this
["5094","5651","5812"] - which im struggling to get right

I put the stringified data in a variable and put it in the tagEditors "initialTags" like this:

    $('#textareabox').tagEditor({
      initialTags: [Array], 
      delimiter: ', ' /* space and comma */
     });

but instead of the results come back as one tag 5651,5812 on button click instead of 5651 5812 which I'm assuming is because of the way its stringified.

Please assist and thank you.

More code can be provided if need be. This is a Javascript / Jquery / HTML project.


Solution

  • You need to transform an Array int to Array string ? then you can use it :

    yourArray.map(String) -- > ["5094","5651","5812"]