Solved

Flex - remove element from array

Posted on 2011-09-28
6
426 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
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 100 total points
ID: 36817764
private function removeAnObjectFromArray(myArray:Array,entryToBeRemoved:String):void{

   myArray.splice(myArray.indexOf(entryToBeRemoved), 1);
                       
}
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 300 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 100 total points
ID: 36897068
Or you can set some empty value too...
arr[5] = "";
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Deleting Objects in flex 1 357
Adobe Air updateFramework 3 260
regular expression:- validate string of numbers 1 417
export web flash file 11 412
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now