It seems like it should be simple, so sorry if I missed something here, but I'm trying to find an easy way to concatenate only non-zero or non-empty strings.
I have several different address fields:
var address; var city; var state; var zip;
Values ββfor them are set based on some form fields on the page and some other js codes.
I want to output the full address in a div , separated by a comma + space, so something like this:
$("#addressDiv").append(address + ", " + city + ", " + state + ", " + zip);
The problem is that one or all of these fields can be empty / empty.
Is there an easy way to combine all non-empty fields in this field group without checking the length of each separately before adding it to the string?
javascript jquery string
froadie Nov 11 '13 at 9:27 am
source share