<?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 Understanding Arcade Code in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1366928#M77019</link>
    <description>&lt;P&gt;Hello and Happy New Year everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So the following &lt;A href="https://bcgis.maps.arcgis.com/home/item.html?id=279310f3c1ec4bbd9fb57639ad859d68" target="_self"&gt;map&lt;/A&gt; computes the Index under Symbology via Arcade which is cool but I would like to add the Index as a column/attribute/field to the data. The code runs fine but since I am still new to Arcade can you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/549511"&gt;@LisaB&lt;/a&gt;&amp;nbsp;as I believe it's your code please explain what the following functions/syntax do? (I have added comments next to the syntax that I am having trouble understanding). Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&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;&lt;LI-CODE lang="c"&gt;var fields = [
  { value: $feature["B17020_calc_pctPovE"], comparison: 13, alias: "Poverty rate" }, // what is value, comparison and it's value and alias doing?
  { value: $feature["B08201_calc_pctNoVehE"], comparison: 9, alias: "Households without access to a vehicle" },
  { value: $feature["B28002_calc_pctNoIntE"], comparison: 14, alias: "Households without access to internet" },
  { value: $feature["B27010_calc_pctNoInsE"], comparison: 9, alias: "Households without health insurance" },
  { value: $feature["B01001_calc_pctDependE"], comparison: 38, alias: "Dependent population (Ages &amp;lt;18 or 65+)" }
];

function calcFactor(fieldsArray){
    var factorCount = 0 // Why add factorCount?
    var factorTotal = 0 // // Why add factorTotal?
    for(var x in fieldsArray){
        var val = fieldsArray[x].value // What's the syntax doing here?
        var comp = fieldsArray[x].comparison // What's the syntax doing here?
        var indexValue = (val/comp)*100 // Why divide val by comp?
        factorTotal += indexValue // What's the syntax doing here?
        factorCount += 1 // What's the syntax doing here?
    }
    var overallIndex = factorTotal/factorCount  
    var indexText = when(overallIndex &amp;lt; 60, "Lowest Stress", overallIndex &amp;gt;= 60 &amp;amp;&amp;amp; overallIndex &amp;lt; 90, "Low Stress", overallIndex &amp;gt;= 90 &amp;amp;&amp;amp; overallIndex &amp;lt; 110, "Average Stress", overallIndex &amp;gt;= 110 &amp;amp;&amp;amp; overallIndex &amp;lt; 140, "High Stress", overallIndex &amp;gt;= 140, "Highest Stress", "N/A")
    return indexText
}&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>Fri, 05 Jan 2024 20:39:53 GMT</pubDate>
    <dc:creator>Ed_</dc:creator>
    <dc:date>2024-01-05T20:39:53Z</dc:date>
    <item>
      <title>Understanding Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1366928#M77019</link>
      <description>&lt;P&gt;Hello and Happy New Year everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So the following &lt;A href="https://bcgis.maps.arcgis.com/home/item.html?id=279310f3c1ec4bbd9fb57639ad859d68" target="_self"&gt;map&lt;/A&gt; computes the Index under Symbology via Arcade which is cool but I would like to add the Index as a column/attribute/field to the data. The code runs fine but since I am still new to Arcade can you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/549511"&gt;@LisaB&lt;/a&gt;&amp;nbsp;as I believe it's your code please explain what the following functions/syntax do? (I have added comments next to the syntax that I am having trouble understanding). Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&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;&lt;LI-CODE lang="c"&gt;var fields = [
  { value: $feature["B17020_calc_pctPovE"], comparison: 13, alias: "Poverty rate" }, // what is value, comparison and it's value and alias doing?
  { value: $feature["B08201_calc_pctNoVehE"], comparison: 9, alias: "Households without access to a vehicle" },
  { value: $feature["B28002_calc_pctNoIntE"], comparison: 14, alias: "Households without access to internet" },
  { value: $feature["B27010_calc_pctNoInsE"], comparison: 9, alias: "Households without health insurance" },
  { value: $feature["B01001_calc_pctDependE"], comparison: 38, alias: "Dependent population (Ages &amp;lt;18 or 65+)" }
];

function calcFactor(fieldsArray){
    var factorCount = 0 // Why add factorCount?
    var factorTotal = 0 // // Why add factorTotal?
    for(var x in fieldsArray){
        var val = fieldsArray[x].value // What's the syntax doing here?
        var comp = fieldsArray[x].comparison // What's the syntax doing here?
        var indexValue = (val/comp)*100 // Why divide val by comp?
        factorTotal += indexValue // What's the syntax doing here?
        factorCount += 1 // What's the syntax doing here?
    }
    var overallIndex = factorTotal/factorCount  
    var indexText = when(overallIndex &amp;lt; 60, "Lowest Stress", overallIndex &amp;gt;= 60 &amp;amp;&amp;amp; overallIndex &amp;lt; 90, "Low Stress", overallIndex &amp;gt;= 90 &amp;amp;&amp;amp; overallIndex &amp;lt; 110, "Average Stress", overallIndex &amp;gt;= 110 &amp;amp;&amp;amp; overallIndex &amp;lt; 140, "High Stress", overallIndex &amp;gt;= 140, "Highest Stress", "N/A")
    return indexText
}&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>Fri, 05 Jan 2024 20:39:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1366928#M77019</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-01-05T20:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1366948#M77027</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;hope all is well, when you have the time, can you please help on this? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 19:40:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1366948#M77027</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-01-05T19:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367104#M77043</link>
      <description>&lt;P&gt;The factorCount and Total are used to calculate the overall index.&lt;/P&gt;&lt;P&gt;line 13 val--&amp;gt; looks in the fieldsArray and grabs the value of the "value" key&lt;/P&gt;&lt;P&gt;line 14 comp --&amp;gt; same thing but the comparison key&lt;/P&gt;&lt;P&gt;line 15&amp;nbsp; get the percentage&lt;/P&gt;&lt;P&gt;line 16 adds the indexValue for this item to the factor total&lt;/P&gt;&lt;P&gt;line 17 just counts how many items you've gone through.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jan 2024 12:45:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367104#M77043</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-01-06T12:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367131#M77048</link>
      <description>&lt;P&gt;Thank you so much for your guidance on this &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;. I have some follow up questionz please, what are lines 1 to 7 doing? Like I know a variable called fields (also is fields a list or a data frame?) is being defined but like we can use {} to define multiple values (value, comparison and alias in this) within a variable? Also value is grabbing values from those respective columns right? And comparison values are hard coded right like 13, 9 and so on? And lastly what's the purpose of defining alias?&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jan 2024 19:24:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367131#M77048</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-01-06T19:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367133#M77049</link>
      <description>&lt;P&gt;Lines 1-7 are a list of dictionaries broken up into different lines for readability. A dictionary has one or more keys, each with a value associated with it. so in this case, the keys are "value", "comparison", and "alias". Each dictionary is structured as&amp;nbsp;&lt;STRONG&gt;{key:value, key2:value2}.&lt;/STRONG&gt; Compare to a list, which is structured with &lt;STRONG&gt;[item1, item2, item 3]&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;So, the function's code takes this list of dictionaries, then for each dictionary, looks up the value for the given key (lines13 and 14).*&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm honestly not sure why there's an alias key in there except maybe for readability; it doesn't seem to get used.&lt;/P&gt;&lt;P&gt;Also, the &lt;EM&gt;fields&lt;/EM&gt; variable is fed into the &lt;EM&gt;calcFactor&lt;/EM&gt; function, inside of which it's called&amp;nbsp;&lt;EM&gt;fieldsArray&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;*Sidenote: Unlike in Python, if you're doing a for loop on a list, the value of the iteration is the index of the item in the list. So you have to look it up by feeding it the index. See below:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Python:&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;list = ["apple", "pear", "banana"]

for l in list:
    print(l)

# "apple"
# "pear"
# "banana"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Arcade:&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// The way you'd expect if coming from Python
var list = ["apple", "pear", "banana"]

for var l in list {
    console(l)
}
// Yields:
// 0
// 1
// 2


// The actual way to get what you want
for var l in list {
    console(list[l])
}
// Yields:
// "apple"
// "pear"
// "banana"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jan 2024 21:17:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367133#M77049</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-01-06T21:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding Arcade Code</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367193#M77061</link>
      <description>&lt;P&gt;Thank you so much for the detailed answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; and also for the comparison explanation between Arcade and Python.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jan 2024 18:54:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/understanding-arcade-code/m-p/1367193#M77061</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-01-07T18:54:17Z</dc:date>
    </item>
  </channel>
</rss>

