In the instance you have provided below yes it will cause an error as by the
time you loop over "test_array" the first index is no longer there and is
undefined.  Even though you are deleting it the length of the array is still
2 so the first time it loops, "item" will be undefined and because it is
undefined or whatever, the method "each()" is not available for a null
value.

To do it properly you should use splice()
(https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objec
ts/Array/splice)

You should really tidy up your array creation also


// Create the arrays
array0 = ['00','01'];
array1 = ['10','11'];

// COPY the arrays into new memory space to make sure 
// dont have a conflict when you remove the array later
test_array = [$A(array0), $A(array1)] ;

// Remove the first item in the array
test_array.splice(0,1)

// Test output
test_array.each(function(items, row){
        items.each(function(i, r){ 
        document.write(r + " : " + i + "<br />" );
        });
});


Steve


-----Original Message-----
From: Shrike [mailto:martin.sile...@gmail.com] 
Sent: Thursday, 6 August 2009 8:39 PM
To: MooTools Users
Subject: [Moo] each error on IE


Hello,

can you help me to solve the IE error on this script?

http://mooshell.net/gYxKu/

no errors with firefox or chrome

var array0 = new Array();
array0[0] = '00';
array0[1] = '01';

var array1 = new Array();
array1[0] = '10';
array1[1] = '11';

var test_array = new Array();

test_array[0] = array0;
test_array[1] = array1;

delete test_array[0];

test_array.each(function(items, row){

        items.each(function(i, r){ // IE error

        alert(i);

        });

});

Reply via email to