Skip to main content

Greetings!

 

I am using a small piece of javascript code to count the numbers of items in a comma seperated list. The code looks like this:

 

let items = inputData.names.split(',');
let length = items.length;
output = ={length: length}];

 

This works great in cases where the list has at least 1 item. However, sometimes the input field will be empty, and then I run into an error. 

 

Is there a way to modify this code so that if the list contains no elements it returns 0, and counts as normal when the list contains items?

 

Thanks!

Hi @Ahmad K - Sure thing! Here’s an example:

let items =  ];
if (inputData.names) {
items = inputData.names.split(",");
}
return r{ length: items.length }];