Split Function Returning One Item When Zero Expected

I am storing some data in a string as a comma separated list and using the Split function to create an array in Wappler when the data is read.

When the string’s value is an empty string, the split function is creating an array with one empty element. In this condition I would expect it to create an empty array.

Question 1
Is this an unfortunate feature of Split, or a bug?

Question 2
If I cannot change this behaviour, then I need to detect if the string value is “” or of length 0 and decide whether to reset the contents of my array or fill it with the split values… and I’m not very clear on how to do that!

Here is my array assignment at the moment:

contact.data.contact.contact_tags.split(",")

So I’m not quite sure how to do this assignment:

contact.data.contact.contact_tags=="" ? ASSIGN_EMPTY_ARRAY : contact.data.contact.contact_tags.split(",")

Thoughts appreciated!

Antony.

Its a feature of javascript, When the string is empty, split returns an array containing one empty string, rather than an empty array.

Hi Antony,

Are you looking for this? It will empty the array from your ternary.

Arr1.empty()

Yeay, that sounds like it will do it… thanks Ken! :slight_smile:

1 Like

@mebeingken, how do you know all these app connect methods? I was asking for a cheat sheet of them, but George doesn’t seem to think there is one…

I wish I could say I had a secret. Beyond trying everything in the editor, I just read almost everything on the forum and store it away for later use.

Well I’m very impressed with your storage facilities!

And thank you for being so present with your knowledge… I really appreciate it!

Best wishes,
Antony.

1 Like

As George explained you already this is available in the UI of the Array component dynamic events… so please use the UI and don’t try to guess the code and edit everything in code view as this won’t really save you much time, as it might look.

Screenshot_56

1 Like