Fabian Posted August 8, 2016 Posted August 8, 2016 Hi, how can I write a rule that will input " | " between values? There will be 15 fields available to use, but not all fields are used all the time. So an example would be: Field1 | Field2 | Field3 or Field1 | Field2 | Field3 | Field4 | Field5 | Field6 or Field1 Quote
step Posted August 8, 2016 Posted August 8, 2016 return [ Field('Field1'), Field('Field2'), Field('Field3'), Field('Field4'), Field('Field5'), Field('Field6'), Field('Field7'), Field('Field8'), Field('Field9'), Field('Field10'), Field('Field11'), Field('Field12'), Field('Field13'), Field('Field14'), Field('Field15') ].filter(String).join(' | '); Or if your fields are really named "Field" + number, you could create the array with a for loop: var fields = []; for (var i = 1; i <= 15; i++) fields.push(Field("Field" + i)); return fields.filter(String).join(' | '); The '.filter(String)' method removes any elements in the array that aren't strings – any fields that aren't used. The '.join(" | ")' method joins the remaining elements in the array with a space, a pipe and a space. Quote
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.