Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

Flex - remove element from array

hi guys

I have code like this

myArray contains  Objects
myArray [0] = object1;
myArray [1] = object2;
myArray [2] = object3;
myArray [3] = object4;


private function removeAnObjectFromArray(myArray:Array,entryToBeRemoved:String):void{
for(var k:Number=0; k< myArray.length; k++){
if(entryToBeRemoved == myArray[k].id){
//here i want to remove the element from myArray. any ideas?
      }
   }
                        
}

should i use splice() ?

thanks
Avatar of dgofman
dgofman
Flag of United States of America image

Yes, this is only one way how you can remove element from an array

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000752.html

shift and unsift will remove from beggining or end
another way you can create a new array and push values what valid for your condition
SOLUTION
Avatar of petiex
petiex
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

Can I remove the elements from the array without
change  the index of elements?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial