It is my understanding that -- from a performance perspective -- direct assignment is more desirable than .push()
when populating an array.
My code is currently as follows:
for each (var e in Collection) {
do {
DB_Query().forEach(function(e){data.push([e.title,e.id])});
} while (pageToken);
}
DB_Query()
method runs a Google Drive query and returns a list.
My issue arises because DB_Query()
can return a list of variable length. As such, if I construct data = new Array(100)
, direct assignment has the potential to go out of bounds.
Is there a method by which I could try
and catch
an Out of Bounds exception to have values directly assigned for the 100 pre-allocated indices, but use .push()
for any overflow? The expectation here is that an OOB exception will not occur often.
Also, I'm not sure if it matters, but I am clearing the array after a counter variable is >=100
using the following method:
while(data.length > 0) {data.pop()}