Most efficient way to replace null values in an array with 0?

Certified Associate Developer

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!

  Discussion posts and replies are publicly visible

Parents
  • Luckily the a!defaultValue() function does exactly what you're looking for! You just have to run it using a!forEach() to apply it to a list of values:

    a!localVariables(
      local!data: {1, 2, null, 4, null, 6},
      a!forEach(
        items: local!data,
        expression: a!defaultValue(
          value: fv!item,
          default: 0
        )
      )
    )

    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.

Reply
  • Luckily the a!defaultValue() function does exactly what you're looking for! You just have to run it using a!forEach() to apply it to a list of values:

    a!localVariables(
      local!data: {1, 2, null, 4, null, 6},
      a!forEach(
        items: local!data,
        expression: a!defaultValue(
          value: fv!item,
          default: 0
        )
      )
    )

    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.

Children
No Data