-
Removing items in a Array based on label
Hello!
I am looking for a way to remove items from an array, via label. Or find a way to get the index number of an array, by specifiying the label name, so i can dynamically remove array items.
Thanks for the help in advance!
Mike
-
Banned
Removing any helpful previous posts I mistakenly contributed to these forums.
See ya FK'ers
Last edited by NTD; 10-19-2006 at 06:14 AM.
-
Hi
Well the truth is, that to my knowledge Flash was no function to retrieve the index number of a specific label in an array or to remove a specific label from an array.
But that’s ok, because you create your own functions and the reuse them as with any other function.
So let’s say I want to find out what index number the word “tree” has in the array
objects = [“apple”,”computer”,”Cd”,”tree”,” girlfriend”];
test=”tree”
position_test = findIndex(objects,test);
function findIndex (objects,test) {
i=0;
while (i<objects.length) {
if (objects[i] == test) {indexnumber= i;}
/*please pay attention if you happen to have two objects with the same name, indexnumer will return the last one. To counteract this you can write a after indexnumber =i; i=objects.length; , in this way the first occurrence of the specified label will be returned */
i++;}
return indexnumber };
To remove the specified label just use splice(i.e. object.splice(position_test,1);
Hope it works
DarkSoul666
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|