<?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: Need help in understanding this function in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192293#M17761</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have questions about the code below. It is part of this &lt;A href="http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/10/07/Using-JavaScript-to-populate-a-ComboBox-with-unique-values.aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;example&lt;/A&gt;:&lt;BR /&gt;&lt;BR /&gt;I added comments/questions in for myself.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var testVals={}; // create object literal (shortcut to creating a new object). This is to hold name:value pairs because an array can only hold single values?&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var features = results.features; //features is a property of query task and has the type of 'graphic'. It is an array.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach (features, function(feature) { //optimized way of doing a for loop, specific to dojo, patterned after HTML5. Let's you apply a function to each element of an array. Feature is each item in the array.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zone = feature.attributes.ZONING_TYPE; //feature in this context is a graphic and attributes is a property
if (!testVals[zone]) { //tests to see if the name:value pair exists
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testVals[zone] = true; //if it it doesn't exist then set this object to true?
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values.push({name:zone}); //push the name:pair of name:&amp;lt;value of zoning type&amp;gt; into the object literal
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;So, if zone has a value of 'residential' then when it gets tested in the if statement, is it testing to see if that value is contained in the testval object? Is it saying, "if zone value does not exist then set that value to true? I'm not exactly sure what exactly is getting set to true and why? Then, it pushes that value into the testval object using name:zone as the pair.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;almost&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All your comments are correct, except the last two lines&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Since testVals is JSON, and not an array&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;testVals[zone] = true&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;actually creates a key "zone" with value true&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;values.push({name:zone}); &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(you left out the var values=[]; ) pushes the json pair into an array&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so you now have 2 variables, one with json values unsorted, and an array with the json pairs added in order.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:40:03 GMT</pubDate>
    <dc:creator>JeffPace</dc:creator>
    <dc:date>2021-12-11T09:40:03Z</dc:date>
    <item>
      <title>Need help in understanding this function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192292#M17760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have questions about the code below. It is part of this &lt;/SPAN&gt;&lt;A href="http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/10/07/Using-JavaScript-to-populate-a-ComboBox-with-unique-values.aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;example&lt;/A&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added comments/questions in for myself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var testVals={}; // create object literal (shortcut to creating a new object). This is to hold name:value pairs because an array can only hold single values?&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var features = results.features; //features is a property of query task and has the type of 'graphic'. It is an array.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach (features, function(feature) { //optimized way of doing a for loop, specific to dojo, patterned after HTML5. Let's you apply a function to each element of an array. Feature is each item in the array.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zone = feature.attributes.ZONING_TYPE; //feature in this context is a graphic and attributes is a property
if (!testVals[zone]) { //tests to see if the name:value pair exists
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testVals[zone] = true; //if it it doesn't exist then set this object to true?
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values.push({name:zone}); //push the name:pair of name:&amp;lt;value of zoning type&amp;gt; into the object literal
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, if zone has a value of 'residential' then when it gets tested in the if statement, is it testing to see if that value is contained in the testval object? Is it saying, "if zone value does not exist then set that value to true? I'm not exactly sure what exactly is getting set to true and why? Then, it pushes that value into the testval object using name:zone as the pair.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:40:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192292#M17760</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2021-12-11T09:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in understanding this function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192293#M17761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have questions about the code below. It is part of this &lt;A href="http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/10/07/Using-JavaScript-to-populate-a-ComboBox-with-unique-values.aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;example&lt;/A&gt;:&lt;BR /&gt;&lt;BR /&gt;I added comments/questions in for myself.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var testVals={}; // create object literal (shortcut to creating a new object). This is to hold name:value pairs because an array can only hold single values?&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var features = results.features; //features is a property of query task and has the type of 'graphic'. It is an array.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.forEach (features, function(feature) { //optimized way of doing a for loop, specific to dojo, patterned after HTML5. Let's you apply a function to each element of an array. Feature is each item in the array.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zone = feature.attributes.ZONING_TYPE; //feature in this context is a graphic and attributes is a property
if (!testVals[zone]) { //tests to see if the name:value pair exists
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testVals[zone] = true; //if it it doesn't exist then set this object to true?
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values.push({name:zone}); //push the name:pair of name:&amp;lt;value of zoning type&amp;gt; into the object literal
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;So, if zone has a value of 'residential' then when it gets tested in the if statement, is it testing to see if that value is contained in the testval object? Is it saying, "if zone value does not exist then set that value to true? I'm not exactly sure what exactly is getting set to true and why? Then, it pushes that value into the testval object using name:zone as the pair.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;almost&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All your comments are correct, except the last two lines&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Since testVals is JSON, and not an array&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;testVals[zone] = true&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;actually creates a key "zone" with value true&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;values.push({name:zone}); &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(you left out the var values=[]; ) pushes the json pair into an array&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so you now have 2 variables, one with json values unsorted, and an array with the json pairs added in order.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:40:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192293#M17761</guid>
      <dc:creator>JeffPace</dc:creator>
      <dc:date>2021-12-11T09:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in understanding this function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192294#M17762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;almost&lt;BR /&gt;&lt;BR /&gt;All your comments are correct, except the last two lines&lt;BR /&gt;Since testVals is JSON, and not an array&lt;BR /&gt;testVals[zone] = true&lt;BR /&gt;actually creates a key "zone" with value true&lt;BR /&gt;&lt;BR /&gt;values.push({name:zone}); &lt;BR /&gt;(you left out the var values=[]; ) pushes the json pair into an array&lt;BR /&gt;&lt;BR /&gt;so you now have 2 variables, one with json values unsorted, and an array with the json pairs added in order.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How would I have known that this was JSON other than more experience and someone pointing it out to me?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok, so, testVals ends up looking like this: {name:residential, name:industrial, etc} or {residential:true, industrial:true, etc}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then the array:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;values = [{"name:residential"},{name:industrial}]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and how does it sort (add them in order)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 18:30:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192294#M17762</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2011-11-04T18:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help in understanding this function</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192295#M17763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;How would I have known that this was JSON other than more experience and someone pointing it out to me?&lt;BR /&gt;&lt;BR /&gt;Ok, so, testVals ends up looking like this: {name:residential, name:industrial, etc} or {residential:true, industrial:true, etc}&lt;BR /&gt;&lt;BR /&gt;then the array:&lt;BR /&gt;&lt;BR /&gt;values = [{"name:residential"},{name:industrial}]&lt;BR /&gt;&lt;BR /&gt;and how does it sort (add them in order)?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;JSON is {} with key value pairs.&amp;nbsp; It is just an object with some formatting (JavaScript Object Notation).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;testVals = {"residential":true, "industrial":true} is correct.&amp;nbsp; Note that json is unsorted, so to retrieve the value you would say testVals.residential (which would return the boolean true in this case)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;values is an array , and the push method adds values to the end as it loops through.&amp;nbsp; (unshift would add to the beginning) so values[0] would return JSON of {"residential":true}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so values[0].residential = true and values[1].industrial = true&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 19:46:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/need-help-in-understanding-this-function/m-p/192295#M17763</guid>
      <dc:creator>JeffPace</dc:creator>
      <dc:date>2011-11-04T19:46:23Z</dc:date>
    </item>
  </channel>
</rss>

