?
Solved

Flex - remove element from array

Posted on 2011-09-28
6
Medium Priority
?
446 Views
Last Modified: 2012-05-12
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
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 36720290
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
 
LVL 29

Expert Comment

by:dgofman
ID: 36720297
another way you can create a new array and push values what valid for your condition
0
 
LVL 11

Assisted Solution

by:petiex
petiex earned 400 total points
ID: 36817764
private function removeAnObjectFromArray(myArray:Array,entryToBeRemoved:String):void{

   myArray.splice(myArray.indexOf(entryToBeRemoved), 1);
                       
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:royjayd
ID: 36818844
Can I remove the elements from the array without
change  the index of elements?
0
 
LVL 29

Accepted Solution

by:
dgofman earned 1200 total points
ID: 36818923
set an element index to null

array[5] = null;

(but in your code validate if value is NULL
0
 
LVL 2

Assisted Solution

by:VickyMad
VickyMad earned 400 total points
ID: 36897068
Or you can set some empty value too...
arr[5] = "";
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question