# Merging parts of 2 arrays...(thousands entries)...with conditional loop

**URL:** <https://forum.kirupa.com/t/merging-parts-of-2-arrays-thousands-entries-with-conditional-loop/190185>\
**Category:** flash\
**Created:** [June 9, 2006, 10:08am UTC](https://forum.kirupa.com/t/merging-parts-of-2-arrays-thousands-entries-with-conditional-loop/190185 "2006-06-09T10:08:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayme65](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@Jayme65](https://forum.kirupa.com/u/Jayme65)\
**Post date:** [June 9, 2006, 10:08am UTC](https://forum.kirupa.com/t/merging-parts-of-2-arrays-thousands-entries-with-conditional-loop/190185/1 "2006-06-09T10:08:23Z")

</div>

Not really a script to correct that I’m submitting you…but a request on a “how-to” 😉

```auto

//Two arrays with 2 elements each.I want to check if they share a value in common...
array1 = new Array();
array2 = new Array();
//
for (i=0; i<5000; i++) {
 attribute1 = "worda"+i;
 atrribute2 = "wordb"+i;
 array1.push({Element1:attribute1, Element2:attribute2});
}
//
for (i=0; i<5000; i++) {
 attribute1 = "wordc"+i;
 atrribute2 = "wordd"+i;
 array2.push({Element1:attribute1, Element2:attribute2});
}
//Now, I want to check if the "Element1" of array2 match the "Element1" of array1
//If this is the case, I want to add "Element2" of array2 to a third one in the array1
//So that I end up with array1 containing Element1:attribute1, Element2:attribute2, Element3:attribute3
//So I had thought of a conditional loop like this:
for (var i:Number = 0; i<array1.length; i++) {
 for (var ii:Number = 0; ii<i<array2.length; ii++) {
  if (array1*.Element1 == array2[ii].Element1) {
   array1.push({Element3:array2[ii].Element2});
  }
 }
}
//But of course if I do like that, the SWF gets mad and instable;-) (25.000.000 iterations);-)
//
// So what is the proper way to achieve something similar to this?

```

IMPORTANT:  
The script joined is of course just an example to illustrate my problem;-)  
In my real application, I’ve actually created a named array with element1 as key…so that I can address it directly by it’s name.  
The problem is that - in my real application - the array2 element doesn’t share a name in common with element1 (so I could address it by its name…as just told you,using named array) but with element5 !  
So how to achieve this efficiently?
