header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
khze86
Points:0
Posts:0

2/21/2010 9:40:50 PM

Title: compare two arrays


Hi..

Let say..

array1 = [1,2,3,4,5];
array2 = [2,4];

I want to remove the elements that exists in both arrays.
So to achieve..

array3 = [1,3,5];



1
Dave
Points: 970
Posts:1
2/21/2010 10:06:18 PM



you can run for loop on small array to see if its elements exist in the big array . The existing element can be removed using array.splice(startIndex,count); method

2
HMS
Points: 280
Posts:0
2/21/2010 10:17:11 PM




private function compareArray():void{
	var array1:Array = new Array(1,2,3,4,5);
	var array2:Array = new Array(2,4); 
	for(var i:int;i<array2.length;i++){
		for(var a:int;a<array1.length;a++){
						
			if(array2[i]== array1[a]){
				array1.splice(a,a+1);
			}
						
		}
					
	}
				trace(array1)
			}



3
HMS
Points: 280
Posts:0
2/21/2010 11:07:25 PM



Sorry here is a fix .


private function compareArray():void{
	var array1:Array = new Array(1,2,3,4,5);
	var array2:Array = new Array(2,4); 
	for(var i:int=0;i<array2.length;i++){
		
		for(var a:int=0;a<array1.length;a++){
			
			if(array2[i]== array1[a]){
				array1.splice(a,1);
			}
			
		}
		
	}
	trace(array1)
}




Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 2+5 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions