Javascript list sorting

I'm trying to make a fast javascript version of the sort block, but I cannot get a list to input correctly. I've never really used javascript before, so any help is appreciated.
My block works when I define the variable in the block, like this:

JS test script pic

But it does not work if I try to use a list as an input, like this:

JS test script pic (1)

or like this:

JS test script pic (2)

Thanks in advance!

Hi @legoman3.14

Your only problem is a list is not just a JS array: it is a Snap! object.

So, you need to convert to an array:
var sort = list.asArray();

Joan

Ok. Thanks for the quick reply!

To get it back to a list, use List([/* items in array */])