Thanks for your exhaustive explanation !
I've solved this issue following:
var _myArray = myArray.clone();
_myArray.each( function(content, index) {
delete content; myArray.splice(index,1);
});
delete _myArray;
On Jun 23, 10:39 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> That's because you're modifying the array's contents within the
> iterator, which is pretty much a no-no. (You can modify the things
> each array element points to, but changing the actual content of the
> array is problematic.) Just glancing at the #_each method in Array
> (which is what #each calls) in prototype.js would reveal why:
>
> _each: function(iterator) {
> for (var i = 0, length = this.length; i < length; i++)
> iterator(this[i]);
> },
>
> So #each probably isn't the best way to approach this. Even if it
> were, re-splicing the array every time is also going to be seriously
> inefficient.
>
> The good news is that all you need to do is set the array's length to
> 0. You can do that directly, or call the tempting Prototype
> Array#clear method:http://www.prototypejs.org/api/array/clear
>
> Setting the array's length automatically deletes any properties that
> the new length would leave out; see the ECMA spec, Section
> 15.4:http://www.ecma-international.org/publications/standards/Ecma-262.htm
>
> Hope this helps,
> --
> T.J. Crowder
> tj / crowder software / com
>
> On Jun 23, 4:13 am, mocambo <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to remove all objects and object references from myArray.
> > But code below brakes before last iteration - myArray contains still
> > one element.
>
> > myArray.each( function(content, index) {
> > delete content; myArray.splice(index,1);
>
> > });
>
> > Is there any solution, how I can decrease this array inside #each ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---