Array not really an array?

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

Array not really an array?

Postby jgarfield » Fri Oct 05, 2012 7:18 pm

Here's the setup
Code: Select all
//oDataset is a dataset created by a recent query
var aNumbers = oDataset.getColumnAsArray(1); //Column 1 is a column of numbers;
var nMin = Math.min.apply(Math, aNumbers);


This will throw the following exception
TypeError: second argument to Function.prototype.apply must be an array


However, if you concatenate the result of getColumnAsArray to an empty array
Code: Select all
//oDataset is a dataset created by a recent query
var aNumbers = [].concat(oDataset.getColumnAsArray(1)); //Column 1 is a column of numbers;
var nMin = Math.min.apply(Math, aNumbers);
it works just fine.

What's going on here? getColumnAsArray doesn't really return an array, just an array-like-object?

Servoy Version: 5.2.14 - build 1027
Programmer.
adBlocks
http://www.adblocks.com
jgarfield
 
Posts: 223
Joined: Wed Sep 28, 2005 9:02 pm
Location: Boston, US

Re: Array not really an array?

Postby jcompagner » Mon Oct 08, 2012 5:30 pm

that returns a java Array (NativeJavaArray) those are quite the same as a native javascript array (NativeArray) for 97% of the use cases, but i guess not in this particular case.

If you do a concat then a new (real js array) is created and returned.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Array not really an array?

Postby jgarfield » Sat Oct 13, 2012 7:14 pm

Interesting. I think this probably explains some issues I've had using the result of getColumnAsArray() with VelocityReports as well.

Logged the case at https://support.servoy.com/browse/SVY-3226
Programmer.
adBlocks
http://www.adblocks.com
jgarfield
 
Posts: 223
Joined: Wed Sep 28, 2005 9:02 pm
Location: Boston, US


Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: No registered users and 2 guests