JS arrays when posted directly to Max window

justin's icon

I'm just a bit curious what happens when I fill a variable with an array (e.g. myArray [0 0 0 0]), and then print this to the Max window via post(). The result is: 0,0,0,0

Whereas if I go back out v8 > print it comes out as expected e.g. 0 0 0 0.

Just seems a bit confusing...

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

A javascript array and a Max list are just different data types in different environments.


0,0,0,0 is how arrays in js are typically printed, which makes sense since array elements are separated by commas, like so: let my_array = [0, 0, 0, 0]

When you send a javascript array out of js with outlet(), it gets converted to a Max list, which is kind of a Max-specific type of array, with elements separated by a space, and this is why [print] gives you 0 0 0 0

But since Max 8.6 (I think?) there is this new Max array type, with all array.* objects, which is closer to what a js array can be. If you use outlet_array() instead of outlet(), the js array gets converted to a Max array, which will print as something like: array u486009809 = [ 0, 0, 0, 0 ]

Max Patch
Copy patch and select New From Clipboard in Max.

justin's icon

Thanks for the explanation, I've been around a while but not caught up with recent changes in Max.