[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2243
  • Last Modified:

Add data to an ArrayCollection

I have two array collections, and they both have a field in common: sourceCode

I would like to push the data from the 2nd into the first. What's the best way to accomplish this?
0
hallikpapa
Asked:
hallikpapa
  • 2
1 Solution
 
lexxwernCommented:
If you want to merge two array collections, you will use the addAll() method. Example below:
var ac1:ArrayCollection;
var ac2:ArrayCollection;
 
// .. .some code ...
 
// merge ac2 into ac1
ac1.addAll( ac2 );
 
// merge ac2 into ac1 at index 5
ac1.addAllAt( ac2, 5 );
 
// add single object
ac1.addItem( new Object );

Open in new window

0
 
hallikpapaAuthor Commented:
Thanks. So would I use a cursor on ac1, and then loop through ac2, and when there is a match on the sourceCode on ac1 == ac2, push ac2 into ac1 on that index...somehow?

Mind showing an example? In my scenario, ac2 will have a lot more sourceCode(s) than ac1. So I only want to push it if there is a match.
0
 
lexxwernCommented:
Try something like this:
var ac1:ArrayCollection;
var ac2:ArrayCollection;
 
// .. some code ..
 
var currentAc1Object:Object;
var currentAc2Object:Object;
 
for each( currentAc1Object in ac1 ) {
   for each( currentAc1Object in ac2 ) {
      if( currentAc1Object.sourceCode == currentAc2Object.sourceCode ) {
         ac1.addItemAt( currentAc2Object, ac1.getItemIndex(currentAc1Object) + 1 );
      }
   }
}

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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