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
royjaydAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dgofmanConnect With a Mentor Commented:
set an element index to null

array[5] = null;

(but in your code validate if value is NULL
0
 
dgofmanCommented:
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
0
 
dgofmanCommented:
another way you can create a new array and push values what valid for your condition
0
Get Certified for a Job in Cybersecurity

Want an exciting career in an emerging field? Earn your MS in Cybersecurity and get certified in ethical hacking or computer forensic investigation. WGU’s MSCSIA degree program was designed to meet the most recent U.S. Department of Homeland Security (DHS) and NSA guidelines.  

 
petiexConnect With a Mentor Commented:
private function removeAnObjectFromArray(myArray:Array,entryToBeRemoved:String):void{

   myArray.splice(myArray.indexOf(entryToBeRemoved), 1);
                       
}
0
 
royjaydAuthor Commented:
Can I remove the elements from the array without
change  the index of elements?
0
 
VickyMadConnect With a Mentor Commented:
Or you can set some empty value too...
arr[5] = "";
0
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.

All Courses

From novice to tech pro — start learning today.