It's the last bit that's especially incorrect. It should say:
"The splice() method is called a second time using the parameters 1, 0, and the spliced array to assign [spinach,[cilantro,onion],green pepper,avocado] to vegetables."
And as I mentioned, the bit about "one or more comma-separated values, or an array" should be stricken as it implies that a passed in array gets special treatment.
The for each loop does not process the array in order. The traversal order is documented as not reliable, but actually seems to always return elements in the order which they are added to the array.
Try this using a straight for loop. (I haven't, so you could be correct about a bug)
Tracy
From: [email protected] [mailto:[email protected]] On Behalf Of Pan Troglodytes
Sent: Tuesday, September 26, 2006 11:38 AM
To: flexcoders
Subject: [flexcoders] bug in Array.splice?
Either there is a bug in Array.splice, or the documentation is off.
>From the help:
Example
The following code creates the Array objectvegetableswith the elements[spinach, green pepper, cilantro, onion, avocado]. Thesplice()method is then called with the parameters 2 and 2, which assignscilantroandonionto thesplicedarray. Thevegetablesarray then contains[spinach,green pepper,avocado]. Thesplice()method is called a second time using the parameters 1, 0, and thesplicedarray to assign[spinach,cilantro,onion,green pepper,avocado]tovegetables.var vegetables:Array = new Array("spinach",
"green pepper",
"cilantro",
"onion",
"avocado");
var spliced:Array = vegetables.splice(2, 2);
trace(vegetables); // spinach,green pepper,avocado
trace(spliced); // cilantro,onion
vegetables.splice(1, 0, spliced);
trace(vegetables); // spinach,cilantro,onion,green pepper,avocado
However, this is not the case. When you pass an array as the third argument to splice, it adds the target ARRAY to the original array. It does not insert the VALUES in the target array.
if you add
for each (var o:Object in vegetables)
trace(typeof(o), o.toString());
you will get:
string spinach
object cilantro,onion
string green pepper
string avocado
So, is this a bug or intended behavior? I could see how it could go either way. However, it seems the example in the documentation should be fixed. I'm thinking it was intended that a passed-in array would be disassembled and its components added. Otherwise, why say "one or more comma-separated values, or an array, to insert into the array"? Singling out array makes no sense, as it would be treated like any other value passed in.
--
Jason
--
Jason __._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
| Software development tool | Software development | Software development services |
| Home design software | Software development company |
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___

