Remove comma from jQuery array

forms, javascript, jquery, php, string

Solution

Since you are using an array use Array.join() with the separator as `' '`

"<input type='hidden' name='Perspective' value='" + newListASource.join(' ') + "'>"

Problem

Problem: I have an array in JS that looks like this: ``` ["intelligence", "skin", "weight", "volume"] ``` This is stored in a var called "newListASource". I apply this var to a form and then submit it using POST. ``` // Form destination var formUrl = 'explorer.php', // Generate the form $form = $("<form action='"+ formUrl +"' method='post'></form>") .append("<input type='hidden' name='Perspective' value='" + newListASource + "'>") .append("<input type='hidden' name='form_submitted' value='true'>") .appendTo('body'); // Submit the form $form.submit(); ``` When I pick it up through PHP and print it out, it gives me a string with commas. For instance: ``` skin,weight,intelligence,volume ``` Desired output I would like is (with trimmed spaces in the beginning and end): ``` skin weight intelligence volume ```

Original source