How can I return all individual array items as separate lines of text?

242
2
Jump to solution
09-29-2021 11:21 AM
ColtonPhillips
New Contributor II

Hello,

 

I'm working in arcade and I am trying to write an expression that gives me the value of a field and convert it to text.

What I did was create an Array that stores all non-null values in to the array. From there, I want the array to return the individual text value for each item in the array. For example....

 

['orange', 'apple', 'banana']

>orange

>apple

>banana

 

What I am getting though is just a return of the first item in the array with the code below. Is my For loop wrong?

 

var i = 0;

var links = [];

function addValue(feat){

if(!IsEmpty(feat)) {

links[i++] = feat;}

};

addValue($feature["PDF_LINK_01"]);

addValue($feature["PDF_LINK_02"]);

addValue($feature["PDF_LINK_03"]);

addValue($feature["PDF_LINK_04"]);

addValue($feature["PDF_LINK_05"]);

addValue($feature["PDF_LINK_06"]);

addValue($feature["PDF_LINK_07"]);

addValue($feature["PDF_LINK_08"]);

addValue($feature["PDF_LINK_09"]);

addValue($feature["PDF_LINK_10"]);

addValue($feature["PDF_LINK_11"]);

addValue($feature["PDF_LINK_12"]);

addValue($feature["PDF_LINK_13"]);

addValue($feature["PDF_LINK_14"]);

addValue($feature["PDF_LINK_15"]);

addValue($feature["PDF_LINK_16"]);

addValue($feature["PDF_LINK_17"]);

addValue($feature["PDF_LINK_18"]);

addValue($feature["PDF_LINK_19"]);

addValue($feature["PDF_LINK_20"]);



for(var k in links){

return links[k]

};

 

 

The above only returns "PDF_LINK_01".

If I take out the For loop, it returns ['PDF_LINK_01', 'PDF_LINK_02', 'PDF_LINK_03', 'PDF_LINK_04']

 

Any help is appreciated

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

I'm assuming this is Arcade? The return statement will exit the function immediately, which is why it only returns the first value. You would need to build a multiline string within your for loop and then return it after the loop has finished.

However, you can use the Concatenate() function to put everything together with a NewLine and you don't even need a for loop.

 

return Concatenate(links, TextFormatting.NewLine)

 

View solution in original post

2 Replies
BlakeTerhune
MVP Regular Contributor

I'm assuming this is Arcade? The return statement will exit the function immediately, which is why it only returns the first value. You would need to build a multiline string within your for loop and then return it after the loop has finished.

However, you can use the Concatenate() function to put everything together with a NewLine and you don't even need a for loop.

 

return Concatenate(links, TextFormatting.NewLine)

 

ColtonPhillips
New Contributor II

Thank you! I tried it with 'return concatenate' and that still only gave one link so I took out return and it gave all of the links. I knew I was close, I was just burnt-out looking at it so thanks again for the help!

0 Kudos