• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

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
0
royjayd
Asked:
royjayd
3 Solutions
 
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
 
petiexCommented:
private function removeAnObjectFromArray(myArray:Array,entryToBeRemoved:String):void{

   myArray.splice(myArray.indexOf(entryToBeRemoved), 1);
                       
}
0
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
royjaydAuthor Commented:
Can I remove the elements from the array without
change  the index of elements?
0
 
dgofmanCommented:
set an element index to null

array[5] = null;

(but in your code validate if value is NULL
0
 
VickyMadCommented:
Or you can set some empty value too...
arr[5] = "";
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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