Solved

Flex - remove element from array

Posted on 2011-09-28
6
443 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 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