# How to push a dynamic number of elements onto an associative array?

**URL:** <https://forum.kirupa.com/t/how-to-push-a-dynamic-number-of-elements-onto-an-associative-array/235400>\
**Category:** flash\
**Created:** [August 10, 2007, 6:27pm UTC](https://forum.kirupa.com/t/how-to-push-a-dynamic-number-of-elements-onto-an-associative-array/235400 "2007-08-10T18:27:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwiley63](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mwiley63](https://forum.kirupa.com/u/mwiley63)\
**Post date:** [August 10, 2007, 6:27pm UTC](https://forum.kirupa.com/t/how-to-push-a-dynamic-number-of-elements-onto-an-associative-array/235400/1 "2007-08-10T18:27:24Z")

</div>

Hello,

I have been working with flash remoting in actionscript 3.0 and there is no result set class. I’m fairly new to AS3, but I am very fluent with AS2, and so far the migration has been easy.

I would like to create a result set class myself, but I am stuck on one part, pushing the dynamic number of elements onto the array, let me show you what I mean:

{ // start result function  
var totalCount:Number = rs.serverInfo.totalCount; // # of records returned  
var queryString:String = rs.serverInfo.intialData; // query string, each value separated by a comma  
var queryArray:Array = new Array();  
queryArray = queryString.split(",");  
var columnString:String = rs.serverInfo.columnNames; // names of the columns, separated by a comma  
var columnArray:Array = new Array();  
columnArray = columnString.split(",");  
var columnLength:Number = columnArray.length;

var myResultSet:Array = new Array();  
// now I have the column names stored in columnArray, and the records stored in queryArray, I would like to make myResultSet an associative array with the column names matching the records. The records come back in the same order the column names do, so keep a recordPosition variable like this:

var recordPosition:Number = 0;  
var columnPos:Number = 0;  
for(var i:int = 0; i \< columnLength; i ++){  
recordPosition = i \* columnLength;  
// this is the part i’m stuck on, i’m currently hard coding my parsing of the query object now because of this, also I don’t know if this is how you eval() correctly in AS 3.0  
queryArray.push({[columnArray[columnPos]]: queryArray\*, … [columnArray[columnPos+columnLength-1]]: queryArray[i+columnLength-1]);  
}  
}  
From all the examples I’ve seen you have to push all the elements into the array at once, statically. I think it may just be some kind of concept I am missing, because I want to loop inside of the push(), but I know that is not possible.

Can anyone enlighten me on this?
