• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

AS3 Merge Arrays in Turn

I have two arrays:
Animals: (cat, dog, mouse)
Colors: (red, blue, yellow, green)

I would like to merge them into a third array, pulling a record from each source array in turn, with the remainder just being added to the end (cat, red, dog, blue, mouse, yellow, green).

Is there a way to do this in AS3?

Thanks in advance.
  • 2
1 Solution
var animals:Array = ["cat", "dog", "mouse", "frog"];
                        var colors:Array = ["red", "blue", "yellow", "green"];
                        var combine:Array = animals.slice(0);
                        var min:uint = Math.min(animals.length, colors.length);
                        for(var z:uint = 0; z < min; z++)
                              combine.splice((z * 2) + 1, 0,  colors[z]);
                        combine = combine.concat(colors.splice(z));
Nice tutorial for learning all Array functions, I will use for my job interviewers :)
length, slice, splice, concat
tmbdesignAuthor Commented:
Ha! Yeah, it has it all.  Plus it works like a charm.

Thank you so much!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now