JavaScript Support

Hello there -

I have a fairly complex simulation that I am building out with the Lectora V21 application. I am stumped at one spot though.

I have a variable called _Lane2SearchDetails that is instantiated by Lectora and I either add or subtract values based on button clicks. There is a finite amount of information that can be assigned to that _Lane2SearchDetails (z1,z2,z3,z4,z5,z6).

Since this variable essentially is an array separated by commas, I would like to split the array using the str.split(',') function built into JavaScript. My best attempt is in a screenshot below.

Now, when I call that function I always get a minimum of one object in the array length, and it only goes up from there or down as a button is unclicked - but it never goes to 0 if there is no objects in the string or ~~~~null~~~~.

The flow occurs as listed below.

Button 1 Clicked (Enabled): Array length = 2, Array contents = z1,

Button 2 Clicked (Enabled): Array length = 3, Array contents = z1,z2,

Button 3 Clicked (Enabled): Array length = 4, Array contents = z1,z2,z3

Button 1 Clicked (Disabled): Array length = 3, Array contents = z2,z3,

Button 2 Clicked (Disabled): Array length = 2, Array contents = z3,

Button 3 Clicked (Disabled): Array length = 1, Array contents = ~~~null~~~

Unsure why it is giving me the array length of current length + 1.

Anything I am doing wrong (obviously I am)?

Discussion (2)

Crap. I completely forgot about that last bit of "" ... I hate when it's something that "easy".

I appreciate your time @timk .

What's wrong with the length?

When you split "z1," by the comma the resulting array should have two items: "z1" and "" (i.e. an empty item). The term "~~~null~~~" is a placeholder for "" (empty) that Lectora puts in. The moment you leave the Lectora context it is regular text, which makes it the first / only item of the array.

You might try to remove the last comma in the value before you turn it into an array:

tempLaneZonesSearched = tempLaneZonesSearched.substring(0, tempLaneZonesSearched.length - 1);

This actually removes the last character, but that should usually be a comma in your case.

You can also remove the last item of the array:

zoneArray.pop();