Removing empty elements from Array Using Execute JavaScript action

Document ID : KB000029139
Last Modified Date : 14/02/2018
Show Technical Document Details

In this article we manipulate the string array. Specifically we remove empty/blank elements from the array before returning the array to the actions output array object Output1 [String[]]. This article assumes that the flow created in KB article TEC1906837 is available.

Steps to test:

  • Open the expression editor for the "Execute JavaScript code" action -> Script [String] field and replace the existing script contents with the following script:

function checkForEmptyElement(element) {
 if(element.trim().length > 0) {
  return true;
 } else {
  return false;
var myArr = input1.split(/\r\n/);
arrOutput1 = myArr.filter(checkForEmptyElement);


Save the flow and test it. This should result in the "Arrays - Write Array to Text File" action writing a file with 3 lines instead of the six lines generated in TEC1906837.