using .join method to convert array to string without commas

JavascriptJquery

Javascript Problem Overview


> Possible Duplicate:
> array join() method without a separator

I'm using .join() to convert my array to a string so I can output it in a text box as the user selects numbers in a calculator, I'm not entirely sure how I can remove the commas that are also being output in the list however. Can someone advise how this can be achieved or if there is a different approach I should be using?

JS

$(document).ready(function() {
    var total = 0;
    var arr = [];

    //Testing
    $('#calculator').children('.num').on('click', function(e) {
        var clickedNumber = $(this).data('id');
        arr.push(clickedNumber);
        console.log(arr.join());
        e.preventDefault();
    });
});​

JS Fiddle http://jsfiddle.net/CVr25/

Javascript Solutions


Solution 1 - Javascript

Simply like that:

arr.join("")

Solution 2 - Javascript

You can specify an empty string as an argument to join, if no argument is specified a comma is used.

 arr.join('');

http://jsfiddle.net/mowglisanu/CVr25/1/

Solution 3 - Javascript

The .join() method has a parameter for the separator string. If you want it to be empty instead of the default comma, use

arr.join("");

Solution 4 - Javascript

All you need to do is :

arr.join('');

FIDDLE

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionstylerView Question on Stackoverflow
Solution 1 - JavascriptVisioNView Answer on Stackoverflow
Solution 2 - JavascriptMusaView Answer on Stackoverflow
Solution 3 - JavascriptBergiView Answer on Stackoverflow
Solution 4 - JavascriptadeneoView Answer on Stackoverflow