Reputation: 143
What I want my function todo is to return an dynamically generated array that I then can assign to the value of an object parameter, e.g:
var varObj:Object = {
level:level,
scores:getScoreArray()
}
function getScoreArray():Object {
return[
for each(var i:score in myScoreArray){
//append i to the return-array
}
];
}
The resulting varObj should then look something like:
{level:12,scores:[150,240,550]}
thanks in advance Jery
EDIT: So this is what vesper´s answer got me:
private function getTrialsArray():Array {
var array:Array = new Array();
for each(var model:TrialTrackingModel in trialTrackingArray) {
array.push({
level:model.level,
stimulustime:model.stimmulusTime,
inputMethod:model.inputMethod,
reactionTimes:model.reactionTimes.slice(),
answers:model.answers.slice()
});
}
return array;
}
Upvotes: 0
Views: 32
Reputation: 18757
You basically create a new array in that function, populate it, then return the readied array. Like this:
function getScoreArray():Array {
var a:Array=[];
for each(var i in myScoreArray){
a.push[i];
}
return a;
}
In fact, this can be done with more ease using Array:slice()
function.
function getScoreArray():Array { return myScoreArray.slice(); }
Upvotes: 1