Forums > MaxMSP

js how to handle lists that have empty elements.

September 23, 2013 | 3:56 am

Hi,

Im iterating out multiple lists in js like this:

0 0 tracks track1
0 0 tracks track2
0 0 tracks track3

However, sometimes I might have an empty element at the end of the list:

0 0 tracks

I would like to be able to detect that the last list element is empty. I cant seem to do this inside the js object, or outside in Max.

In Max, ive tried using "zl len" to detect the size of the list, but Max seems to believe that the list element is there, even though it is empty.

The same goes for inside the js object. Ive tried using

if (var[3] == "")

Even though the part of the list is empty, there seems to be no way of recognising that it is empty.

Id be really grateful if anyone has any insights to a way of working around this.

UPDATE: Finally ive got it "if (var[3] == 0)"


September 23, 2013 | 8:36 am

An array in js always of the length property. You can probably do something like:

if (yourvar.length < 3)


September 23, 2013 | 8:52 am

If your problem is that the last item of the list may be an empty string, you could use [sadam.empty] to detect that.

HTH,
Ádám


September 23, 2013 | 10:45 am

removing it or replacing it with the symbol "zzz" might be also an option.


Viewing 4 posts - 1 through 4 (of 4 total)