09-29-2001, 01:11 PM
|
#1
|
|
power to the pinK
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
|
remove item from array
Please, could someone tell me how to remove an item from an array please?
for example:
remove = "";
MyArray = [1, 2, 3, 4, 5, 6];
if "remove"= 4 I want :
MyArray = [1, 2, 3, 5, 6];
(or to create a new array?)
How can I do this?
Thanks in advance,
K
|
|
|
09-29-2001, 11:15 PM
|
#2
|
|
[^\d\D]
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
|
splice() is what you need, baby...
...It can add or subtract elements from an array. In your example...
Code:
MyArray.splice(3, 1);
This will effectively remove the 4th element from the array. Remember that array elements begin with "0"...
yeah?
|
|
|
09-30-2001, 04:29 PM
|
#3
|
|
power to the pinK
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
|
Thanks very much, I'll go and try that now.
Although I have a query - if the first number removes the corresponding element from an array, what does the second number do?
cheers
K
|
|
|
09-30-2001, 06:02 PM
|
#4
|
|
done
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
|
i believe the first number tells flash where to start pulling elements out of the array, the second number tells flash how many elements to pull out of the array.
i'm not sure exactly, so check help in flash
__________________
tg
---
what the hell was i thinking?
|
|
|
09-30-2001, 08:17 PM
|
#5
|
|
[^\d\D]
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
|
Right-o! The second argument tells the interpreter how many elements to get rid of! (referred to as the deleteCount)
If you don't give deleteCount, it'll remove the remaining elements...
Code:
var foo = new Array("1", "2", "3", "4", "5", "6");
foo.splice(4);
//foo is now 1, 2, 3, 4
foo.splice(1,1);
//foo is now 1, 3, 4
foo.splice(1, 0, "blah")
//used splice to insert "blah" into foo.
//foo is now 1, blah, 3, 4
//Note the use of zero for the deleteCount
Cool, eh?
|
|
|
10-01-2001, 02:45 PM
|
#6
|
|
power to the pinK
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
|
awesome
thank you very much, both of you
I think I actually understand splice now, well, a bit clearer now anyway! I'd been wading through the tutorials/function library in dispair because although people had been fantastic enough to submit code I didn't have a clue how to interpret it to make it useful. Feel like I'm getting somewhere now.
cheers
K
|
|
|
10-02-2001, 01:29 AM
|
#7
|
|
ActionScript.org Founder
Join Date: Nov 2000
Location: New York
Posts: 8,736
|
Remember that like most of the prototypes which ship with Flash are very innefficient. People have ade their own Splice functions and posted them about the place. Apparently they're 40% faster if you want to look around...
__________________
Cheers
Jesse Stratford
ActionScript.org Cofounder
Please don't email or PM me Flash questions, that's what the Forums are for!
Please don't rely on me reading my PMs either. Email me about important stuff.
|
|
|
10-02-2001, 04:17 AM
|
#8
|
|
done
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
|
prototype is a great place to find some wonderful code/prototypes. the folks there have it set up so users keep the database updated, and can comment on other code available to everyone.
the bad news is they are down right now, but hopefully will be back soon.
here is the dress http://www.layer51.com/proto/
__________________
tg
---
what the hell was i thinking?
|
|
|
10-02-2001, 10:16 AM
|
#9
|
|
[^\d\D]
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
|
Thanks for the info tg! Haven't checked it out yet but look forward to it!
|
|
|
10-15-2001, 08:27 PM
|
#10
|
|
power to the pinK
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
|
TG - fantastic, that link you posted is now working again (hoorah) and I've just checked it out. Looks like a great site, thanks very much for the tip.
cheers
K
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 05:12 AM.
///
|
|