Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

merging arrays

Community Beginner ,
Jan 12, 2016 Jan 12, 2016

Hi,

I am new to as3 and need your help.

I would like to combine two arrays such that the elements of each array follow each other in alternating order.

For example, if Array1=(1,2,3) and Array2=(A,B,C), I would like my combined Array to  look like (1,A,2,B,3,C).

When I use the concatenate function the arrays are combined like this: (1,2,3,A,B,C) and this is not what I want.


Please let me know if you know the answer.

Thank you so much.

Melisa

TOPICS
ActionScript
584
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 12, 2016 Jan 12, 2016

One way to do it... you could build a new array from the two using a loop....

var Array1:Array = [1,2,3];

var Array2:Array = ["A","B","C"];

var combinedArray:Array = new Array();


for(var i:int=0; i<Array1.length; i++){
    combinedArray.push(Array1);
    combinedArray.push(Array2);
}

trace(combinedArray);

Translate
LEGEND ,
Jan 12, 2016 Jan 12, 2016

One way to do it... you could build a new array from the two using a loop....

var Array1:Array = [1,2,3];

var Array2:Array = ["A","B","C"];

var combinedArray:Array = new Array();


for(var i:int=0; i<Array1.length; i++){
    combinedArray.push(Array1);
    combinedArray.push(Array2);
}

trace(combinedArray);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 12, 2016 Jan 12, 2016

Dear Ned,

Thank you so much! This is really helpful!  I have been working in this for long hours without any success.
Thanks!

Melisa

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2016 Jan 12, 2016
LATEST

You're welcome Melisa

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines