Forum Moderators: open

Message Too Old, No Replies

alternative to push and pop

         

sneaks

3:50 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



just found out that ie 5:mac doesnt support push and pop of an array. is there a work around?

jonathan

sneaks

4:44 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



for those interested i found an extended array script that works very nicely:

[dithered.com...]

Bernard Marx

4:48 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



..nor does IE 5 Win.

You need to roll your own and add them to the Array.prototype . Incomplete emulations are easy, but making sure you have all possibilities covered is trickier.

I'm going to let someone else take the credit (and the blame):

I have also posted the full code listing for other array method emulations)


// +----------------------------------------------------------------+
// ¦ Array functions that are missing in IE 5.0 ¦
// ¦ Author: Cezary Tomczak [www.gosu.pl] ¦
// ¦ Free for any use as long as all copyright messages are intact. ¦
// +----------------------------------------------------------------+

// Removes the last element from an array
// and returns that element.
if (!Array.prototype.pop) {
Array.prototype.pop = function() {
var last;
if (this.length) {
last = this[this.length - 1];
this.length -= 1;
}
return last¦¦null;
};
}

// Adds one or more elements to the end of an array and returns
// the new length of the array.
if (!Array.prototype.push) {
Array.prototype.push = function() {
for (var i = 0; i < arguments.length; ++i) {
this[this.length] = arguments[i];
}
return this.length;
};
}

[edited by: jatar_k at 3:46 pm (utc) on Oct. 5, 2005]