LyndaEngelage Posted August 26, 2021 Share Posted August 26, 2021 Using Acrobat Pro DC with FusionPro version 10.1.11 I need to join the State and zip with a different "join" of just a space. The following code works except it joins STATE and ZIP CODE with ", " Is there a way to differentiate the joins. var items = [ Field("STREET"), Field("CITY"), Field("STATE"), Field("ZIP CODE") ]; items = items.filter(String); // remove empty items return [ items.slice(0, 4).join(", "), items.slice(4).join(" ") ].filter(String).join("<br>\n"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 26, 2021 Share Posted August 26, 2021 (edited) So, I'm usually in favor of clever ways to use arrays and such to abstract things and reduce repetitive code. If this were something that could be possibly extended to handle more fields in the future, that would be a great way to go. But in this case, you're only ever going to have these few fields, so it might be better to be more straightforward. If you only need a single space, just put the space there: return items.slice(0, 3).join(", ") + " " + items.slice(3); Though really, even that seems a bit unnecessarily complicated. You can be even more straightforward. The whole thing could be one line: return [ Field("STREET"), Field("CITY"), Field("STATE") ].join(", ") + " " + Field("ZIP CODE"); Though even that doesn't save much from the most straightforward approach: return Field("STREET") + ", " + Field("CITY") + ", " + Field("STATE") + " " + Field("ZIP CODE"); I also don't think you need the call to remove empty fields; an address without any of those would presumably be invalid. Unless there's an "Address 2" line, in which case I would just handle that as a special case: var streetAddr = [ Field("Address1"), Field("Address2") ].filter(String); return [ streetAddr, Field("CITY"), Field("STATE") ].join(", ") + " " + Field("ZIP CODE"); Edited August 26, 2021 by Dan Korn Quote Link to comment Share on other sites More sharing options...
LyndaEngelage Posted August 30, 2021 Author Share Posted August 30, 2021 Thank you Dan, The first suggestion worked great. I forgot to mention that if the whole address line was blank I wanted the line suppressed. Also "having no address" was a customer request for business cards. Thanks again for your expertise. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 31, 2021 Share Posted August 31, 2021 I forgot to mention that if the whole address line was blank I wanted the line suppressed. Just Trim the whole thing: return Trim([ Field("STREET"), Field("CITY"), Field("STATE") ].join(", ") + " " + Field("ZIP CODE")); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.