In addition you could make it easier to use like this
Array.implement({
deleteAt : function (index) {
if (index > this.length-1) return;
this.splice(index,1);
}
});
And then just call....
test_array.deleteAt(0);
To be honest I am very surprised something like this isnt already in the
framework
Another option also is to leave what you have and do this...
delete test_array[0];
test_array.clean();
I wouldn't but its an option
Steve
-----Original Message-----
From: Steve Onnis [mailto:[email protected]]
Sent: Friday, 7 August 2009 12:41 AM
To: [email protected]
Subject: [Moo] Re: each error on IE
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:[email protected]]
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);
});
});