<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>if index is set</title><link>https://community.appian.com/discussions/f/user-interface/19336/if-index-is-set</link><description>Hello, 
 How I can check if index is set 
 example: local!startchart[5] 
 if 5 in this array is not set throw 0 for example ?</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: if index is set</title><link>https://community.appian.com/thread/75669?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 14:22:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:90286bbb-e0c1-4c2a-9d9c-2af67ceb3e6d</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Far more flexible is the &lt;em&gt;index()&lt;/em&gt; function.&amp;nbsp; Basically what Stuart already answered below.&lt;/p&gt;
&lt;p&gt;i.e.&amp;nbsp; &lt;em&gt;&lt;strong&gt;index(local!startChart, 5, 0)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if index is set</title><link>https://community.appian.com/thread/75668?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 14:11:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3fc7324d-de43-4ee9-9477-d28fb7beb18a</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;I think it&amp;#39;s simpler than this. fn!index() will look for an item at the index provided and, if not found, can return a default value:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!myArray: {1,2,3,4,5},
  fn!index(local!myArray, 7, 99)
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this example, I have an array of 5 elements, and I&amp;#39;m looking for the value in the 7th position - which doesn&amp;#39;t exist - so I return 99 instead.&lt;/p&gt;
&lt;p&gt;Or have I missed some nuance here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if index is set</title><link>https://community.appian.com/thread/75651?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 02:01:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:eaf342cd-63ac-4288-a98e-9bbe66c767ce</guid><dc:creator>legotx</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;with(
    local!startChart: {
        1,
        2,
        3,
        4
    },
    local!chartIndex: 2,

    if (
        local!chartIndex &amp;gt; count(local!startChart), 
        0, 
        index(local!startChart, local!chartIndex, 0)
    )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I think the index() function will return null if it is not set. But you can replace the last parameter, using&amp;nbsp;&lt;strong&gt;0&lt;/strong&gt; in order to return zero if the index is not set.&lt;/p&gt;
&lt;p&gt;Additionally, you can perform a check before using the value for chartIndex if it is within the bounds of the number of elements of the local!startChart.&lt;/p&gt;
&lt;p&gt;Using the array notation with &amp;quot;variable[index]&amp;quot; format is also not a good practice because the index might be invalid.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: if index is set</title><link>https://community.appian.com/thread/75649?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 01:52:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dcc6b4ee-7ffe-4664-a6c1-bf1ea5fc88ee</guid><dc:creator>Vladimir Vasilev</dc:creator><description>&lt;p&gt;What I have used is:&amp;nbsp;if(count(local!startchart) &amp;lt; 5,0,local!startchart[5]))&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>