I am having a javascript array.
addresses = new Array(document.client.cli_Build.value,
document.client.cli_Address.value,
document.client.cli_City.value,
document.client.cli_State.value,
document.client.cli_Postcode.value,
document.client.cli_Country.value);
document.client.cli_PostalAddress.value = addresses.join(", ");
I have to copy the content of all these array value to the postal address textarea. when i use the above join function, comma has been added for null values. How to remove this extra commas?
Thanks
Or should it be
??
One could also use Array.prototype.reduce().
It reduces an array to a single value, e.g. a string. Like so:
a
holds the intermediate result,b
holds the current element.Underscore is a nice utility library for functional programming and list manipulation:
Edit: And there is a more compact way (Thanks Andrew De Andrade!):