Solved

Flex - remove element from array

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

   myArray.splice(myArray.indexOf(entryToBeRemoved), 1);
                       
}
0
2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Deleting Objects in flex 1 388
AdvancedDataGrid 5 528
Vertical ScrollBar on RichTextArea 2 1,100
Flex Mobile - Problems with returning array results 5 485
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…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

734 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