Creating and array with fields from several arrays

Doing something wrong with this:

I have four arrays holding data:

      id_array:Array;
      last_name_array:Array;
      first_name_array:Array;
      condition_array:Array;

I have a for loop with counter set to the number of items in the arrays, with the idea of inserting data from each array into the fields of the following DiffArray. I am getting Error #1009: Cannot access a property or method of a null object reference and I cant see why.

    for(var i:Number=0; i<Student_counter; i++){
    DiffArray.push({id:id_array[i],first_name:first_name_array[i],last_name:last_name_array[i],condition:condition_array[i]});
    }

Help with this greatly appreciated.

Upvotes: 0

Views: 50

Answers (3)

Andrew Arace
Andrew Arace

Reputation: 457

I assume you're making sure your 4 arrays are all the same length, or at least (Student_counter) long ?

Upvotes: 0

kasavbere
kasavbere

Reputation: 6003

DiffArray should be initialized first.

Upvotes: 0

Eric
Eric

Reputation: 10658

You have to declare your array first : DiffArray:Array = new Array();

Upvotes: 1

Related Questions