Why does this work (returns \"one, two, three\"):
var words = [\'one\', \'two\', \'three\'];
$(\"#main\").append(\'\' + words.join(\", \") + \'
If you are not interested on other Array.prototype
methods, and you want simply to use join
, you can invoke it directly, without converting it to an array:
var displayIt = function() {
return 'the list: ' + Array.prototype.join.call(arguments, ',');
};
Also you might find useful to know that the comma is the default separator, if you don't define a separator, by spec the comma will be used.