<?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>Most efficient way to replace null values in an array with 0?</title><link>https://community.appian.com/discussions/f/best-practices/37474/most-efficient-way-to-replace-null-values-in-an-array-with-0</link><description>Currently using a!forEach and a!isNullOrEmpty to replace all null values in an array of integers with 0, but would love to learn the most efficient way to do so. Is apply() the way to go here? A different function? Many thanks for any and all help!</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Most efficient way to replace null values in an array with 0?</title><link>https://community.appian.com/thread/140395?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2024 12:30:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:04887881-2d06-4f8f-920d-e32af11a5a06</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Luckily the a!defaultValue() function does exactly what you&amp;#39;re looking for! You just have to run it using a!forEach() to apply it to a list of values:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: {1, 2, null, 4, null, 6},
  a!forEach(
    items: local!data,
    expression: a!defaultValue(
      value: fv!item,
      default: 0
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Also you asked about the apply() function - at this point, everything that the apply function does can also be done by a!forEach(), so I recommend using a!forEach() instead if you need to loop over a list of values.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Most efficient way to replace null values in an array with 0?</title><link>https://community.appian.com/thread/140380?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2024 05:33:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:82154e49-3d7f-4bb0-9e4b-62ed8e3322a9</guid><dc:creator>Yogi Patel</dc:creator><description>&lt;p&gt;The following code snippet might be helpful:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: { 1, null, 0, 10, null },
  local!updatedData: a!update(
    local!data,
    wherecontains(tointeger(null()), local!data),
    0
  ),
  local!updatedData
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Most efficient way to replace null values in an array with 0?</title><link>https://community.appian.com/thread/140372?ContentTypeID=1</link><pubDate>Sun, 08 Sep 2024 21:12:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3817804f-4eb6-45d1-a6f1-6220cc89755f</guid><dc:creator>Kumar Agniwesh</dc:creator><description>&lt;p&gt;If you just need to remove the null values from array then I would just to use remove(a!isnull,&amp;lt;array&amp;gt;).&lt;/p&gt;
&lt;p&gt;But if you really have to replace then I would suggest not to use apply.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>