How to trim an array record

Elements in an array can contain whitespaces after the variable. To trim the whitespaces in an array, follow the below steps:

Illustrated in the below image is an example of the flow where we are using the Record Generator as the source step.

image

The Record Generator is populated with data and an array record called “tasks” as shown in the below image.

image

In the below page is the raw output results of the data that is in the Record Generator. Highlighted are the whitespaces that are in each element in the array record.

image

The Calculator step contains the code that is used to trim the whitespaces in the array.

image

Below is the code to copy and paste in your Calculator step:

let inputRecord=input.record;
function deepTrim(object) {
    if (typeof object === 'string') {
        return object.trim();
    } else if (typeof object === 'object') {
        for (var key in object) {
            object[key] = deepTrim(object[key]);
        }
    }
    return object;
}
return {
    tasks:deepTrim(inputRecord.tasks)
};

Illustrated in the below image is the raw output results of the whitespaces in the array being trimmed.

image