<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcade For Loop &amp;amp; Array in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198710#M58110</link>
    <description>&lt;P&gt;There are a few things to address with your expression, but you're most of the way there.&lt;/P&gt;&lt;P&gt;First, you're trying to append to the new array the wrong way. Using += works for numbers and strings, but an array needs to be appended to differently. In the latest versions of Arcade you have access to &lt;STRONG&gt;Push&lt;/STRONG&gt;, which will insert an item into an array.&lt;/P&gt;&lt;P&gt;Also, if your original field is a string, you'll need to convert those to numbers.&lt;/P&gt;&lt;P&gt;And lastly, when you're looping over an array, you access the individual array items with &lt;STRONG&gt;array[index]&lt;/STRONG&gt;, not by calling the index directly, which is just an integer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Try this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var NewArray = []
var OrigArray = split($feature.CONCATENATE_Story_Num, ",")

for (var i in OrigArray) {
  If (Number(OrigArray[i]) != -99) {
    Push(NewArray, OrigArray[i]);
    }
}

return Mean(NewArray)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my result running it against '-99,1,2':&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1659470542914.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/47625iDA5D9D0DE0F9D12B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1659470542914.png" alt="jcarlson_0-1659470542914.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2022 20:02:57 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-08-02T20:02:57Z</dc:date>
    <item>
      <title>Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198705#M58108</link>
      <description>&lt;P&gt;Hi - I'm using ArcPro 3.0.0 and I'm new to Arcade.&amp;nbsp; Using Calculate Field, I trying to write a bit of Arcade code so it loops thru the values of existing field which has a string of concatenated values (i.e.&amp;nbsp; -99,1,2).&amp;nbsp; Where an item in this string &lt;EM&gt;does not equal&lt;/EM&gt; -99, I want to append the value to a new array and then ultimately return the Mean of the NewArray.&amp;nbsp; So, given -99,1,2 the resulting Mean should = 1.5&lt;/P&gt;&lt;P&gt;So, I've tried the following code but it doesn't work.&amp;nbsp; It just returns Null values:&lt;/P&gt;&lt;P&gt;var NewArray = []&lt;BR /&gt;var OrigArray = split($feature.CONCATENATE_Story_Num, ",")&lt;BR /&gt;For (var i in OrigArray) {&lt;BR /&gt;&amp;nbsp; If (i!=-99) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; NewArray+=OrigArray[i];&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;return Mean(NewArray)&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 19:43:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198705#M58108</guid>
      <dc:creator>ChristineSeidel</dc:creator>
      <dc:date>2022-08-02T19:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198709#M58109</link>
      <description>&lt;P&gt;You can use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#filter2" target="_self"&gt;Filter&lt;/A&gt; function to do this&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arr = [-99,1,2];

function isGood(i) {i != -99}

var newarr = Filter(arr, isGood);
return Mean(newarr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 20:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198709#M58109</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-02T20:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198710#M58110</link>
      <description>&lt;P&gt;There are a few things to address with your expression, but you're most of the way there.&lt;/P&gt;&lt;P&gt;First, you're trying to append to the new array the wrong way. Using += works for numbers and strings, but an array needs to be appended to differently. In the latest versions of Arcade you have access to &lt;STRONG&gt;Push&lt;/STRONG&gt;, which will insert an item into an array.&lt;/P&gt;&lt;P&gt;Also, if your original field is a string, you'll need to convert those to numbers.&lt;/P&gt;&lt;P&gt;And lastly, when you're looping over an array, you access the individual array items with &lt;STRONG&gt;array[index]&lt;/STRONG&gt;, not by calling the index directly, which is just an integer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Try this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var NewArray = []
var OrigArray = split($feature.CONCATENATE_Story_Num, ",")

for (var i in OrigArray) {
  If (Number(OrigArray[i]) != -99) {
    Push(NewArray, OrigArray[i]);
    }
}

return Mean(NewArray)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my result running it against '-99,1,2':&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1659470542914.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/47625iDA5D9D0DE0F9D12B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1659470542914.png" alt="jcarlson_0-1659470542914.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 20:02:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198710#M58110</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-02T20:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198712#M58112</link>
      <description>&lt;P&gt;Oh, I like this! Sometimes I forget about the array functions. Combining this with &lt;STRONG&gt;Map&lt;/STRONG&gt; to get the strings to numbers would be really slick.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2022 20:05:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198712#M58112</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-02T20:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198908#M58126</link>
      <description>Thanks for this solution, Josh. This is exactly what I was looking for. While my original input field is a string of concatenated comma delineated numbers, once it's Split and then recognized as an Array, I didn't have to do any other conversion of string to number.&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;-Chris&lt;BR /&gt;&lt;BR /&gt;Chris Seidel (pronouns - she, her, hers)&lt;BR /&gt;Cartographer/GIS Coordinator&lt;BR /&gt;Martha's Vineyard Commission&amp;lt;&amp;gt;&lt;BR /&gt;Dukes County Interactive Maps&amp;lt;&amp;gt;&lt;BR /&gt;Dukes County GIS Data Hub&amp;lt;&amp;gt;&lt;BR /&gt;Mailing: PO Box 1447 Oak Bluffs MA 02557&lt;BR /&gt;Physical: 33 New York Ave Oak Bluffs MA&lt;BR /&gt;Office: 508-693-3453 x120 (Tuesday thru Friday 8:00AM to 4:00PM)&lt;BR /&gt;Saturdays - working from home; please email: seidel@mvcommission.org</description>
      <pubDate>Wed, 03 Aug 2022 12:40:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198908#M58126</guid>
      <dc:creator>ChristineSeidel</dc:creator>
      <dc:date>2022-08-03T12:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198915#M58127</link>
      <description>&lt;P&gt;You're welcome! The Arcade Playground and Pro must behave a little differently under the hood, as I couldn't use mathematical functions against the array when I tested it. But I'm glad you got it to work, regardless!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 13:20:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198915#M58127</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-03T13:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198937#M58130</link>
      <description>&lt;P&gt;It turns out you don't need a Map function, just a minor modification to the Filter function&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arr = "-99,1,2";

function isGood(i) {i != "-99"}

var newarr = Filter(split(arr,","), isGood);
return Mean(newarr);&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Aug 2022 14:44:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198937#M58130</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-03T14:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198950#M58131</link>
      <description>&lt;P&gt;Interesting! Now I'm wondering if I had a typo when I tested it originally. &lt;STRONG&gt;Mean&lt;/STRONG&gt; seems to cast array members to numbers automatically.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 14:57:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198950#M58131</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-03T14:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198965#M58134</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Interesting! Now I'm wondering if I had a typo when I tested it originally. &lt;STRONG&gt;Mean&lt;/STRONG&gt; seems to cast array members to numbers automatically.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, which is why your code worked. Otherwise, you would have had to convert the values in OrigArray to a number when you pushed them into NewArray&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 15:10:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198965#M58134</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-03T15:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198974#M58135</link>
      <description>&lt;P&gt;D'oh!&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/141153"&gt;@ChristineSeidel&lt;/a&gt;I think Ken should get the green checkmark here, he has a much more elegant solution than I, and clearly was more careful in how he wrote his expression. I just got lucky!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 15:27:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1198974#M58135</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-03T15:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1199010#M58139</link>
      <description>&lt;P&gt;Thanks Ken.&amp;nbsp; As Josh says, your solution is quite elegant.&amp;nbsp; Being pretty new to Arcade it was easier for me to follow the logic of the For Loop and building a new array ...but it's great to know more ways around the barn.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;- Chris Seidel&lt;/P&gt;&lt;P&gt;Cartographer - Martha's Vineyard Commission&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 16:35:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1199010#M58139</guid>
      <dc:creator>ChristineSeidel</dc:creator>
      <dc:date>2022-08-03T16:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1199066#M58152</link>
      <description>&lt;P&gt;That's why Josh's replies are always so helpful. He provides a good amount of background information on why things are happening.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 18:18:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1199066#M58152</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-03T18:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1357789#M76060</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I've been trying to apply the great examples in this thread to my circumstance but keep coming up short. I want to convert the text values to number from getData function to the array. I've been trying Push and Number functions but I haven't been able to make it work.&lt;/P&gt;&lt;P&gt;I'm using an address point to query underlying layers, like Plats. There can be multiple Plats overlapping an address point. Ultimately, I want find the most recent Plat and append the Filename to #2 below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "Recorded" date field is formatted mm/dd/yyyy.&lt;/P&gt;&lt;P&gt;I included some commented code that I tried. Any help is appreciated. Thanks in advance!!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var getData = FeatureSetByName($datastore, "Plat", ["Filename", "Recorded"])
var PlatDataInt = Intersects(getData, $feature)

var platlist = ""
//var newarray = []

for (var k in PlatDataInt){
    platlist += Right(k.Recorded, 4) + TextFormatting.NewLine
     //Number(platlist[k]){
       //Push(newarray, platlist[k]);
 //}
}

return platlist
//return Max(platlist)
// #1 if (Val == null) return "https://mywebserver/images/survey/NoImage.pdf" 
// #2 "https://mywebserver/images/survey/Plats/" + Text(Filename)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 00:37:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1357789#M76060</guid>
      <dc:creator>JwHayes</dc:creator>
      <dc:date>2023-12-07T00:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade For Loop &amp; Array</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1358380#M76107</link>
      <description>&lt;P&gt;I was able to get the most recent year from the intersection plats. However, I got so head-down in this I forgot I need to pull the Filename for the most recent plat year.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var getData = FeatureSetByName($datastore, "Plat", ["Filename", "Recorded"])
var platint = Intersects(getData, $feature)

var platlist = []

for (var k in platint){
    var rdate = k.Recorded
    var newdate = Right(rdate, 4)
    var numdate = Number(newdate, '####.')
        Push(platlist, numdate)
        
}
var doc = Max(platlist)

return doc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 00:24:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-for-loop-amp-array/m-p/1358380#M76107</guid>
      <dc:creator>JwHayes</dc:creator>
      <dc:date>2023-12-08T00:24:40Z</dc:date>
    </item>
  </channel>
</rss>

