By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Array.push() not working with IE.

P: n/a
Daz
Hi everyone.

First of all, I would be interested to know if anyone knows of a decent
plugin for IE that validates JavaScript. I am running IE 5, 5.5 and 6
through wine (Windows Emulator) on Linux, so I haven't yet found one.
However, this is my problem:

I have the following piece of script:

// This is just test data...
var books = Array(
{ret:{o:20,u:50},reg:{o:12,u:34},n:"A"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"B"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"C"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"D"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"E"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"F"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"G"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"H"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"I"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"J"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"K"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"L"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"M"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"N"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"O"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"P"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"Q"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"R"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"S"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"T"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"U"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"V"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"W"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"X"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"Y"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"Z"},
{ret:{o:20,u:50},reg:{o:12,u:34},n:"0-9"}
);

function appendTotals()
{
var totalRetiredOwned;
var totalRetiredUnowned;
var totalRegularOwned;
var totalRegularUnowned;
for (var i = 0; i < books.length; i++)
{
totalRetiredOwned += books[i].ret.o;
totalRetiredUnowned += books[i].ret.u;
totalRegularOwned += books[i].reg.o;
totalRegularUnowned += books[i].reg.u;
}
var totals =
{ret:{o:totalRetiredOwned,u:totalRetiredUnowned},
reg:{o:totalRegularOwned,u:totalRegularUnowned},n: "Totals"};
books.push(totals);

}
appendTotals();

IE seems to have a problem with the line that reads
'books.push(totals);' When I comment it out, the rest of the script
runs. When I leave it in, IE throws a wobbler, I get an error and the
script stops. It's all well and good that IE reports that there's an
error, but if only it told me what the fricking error was! I feel that
Microsoft is laughing at me, along with the other users who have to
seriously modify/hack/botch their otherwise, well written scripts in
order to compensate for where IE has gone awry. Even when I change
'books.push(totals);' to 'books.push("blah");', it still gets it's
knickers in a twist. Perhaps JavaScript doesn't allow different data
types in an array? I'm not 100% certain to be honest.

Would anyone please be so kind as to point out where I might be going
wrong? The entire script worls beautifully in Firefox, as always, it's
IE that is 'the thorn in my side', (only replace 'thorn' with '12 inch
spike').

Many thanks in advance.

Seriously confused.

Daz.

Nov 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Daz wrote:
Even when I change
'books.push(totals);' to 'books.push("blah");', it still gets it's
knickers in a twist.
Early versions of IE (<=5?) didn't support Array.push.

Simply create your own push function and add it to Array.prototype to add
this functionalty for any browser that doesn't already have it.
Google it to find examples.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 30 '06 #2

P: n/a
Daz

Matt Kruse wrote:
Daz wrote:
Even when I change
'books.push(totals);' to 'books.push("blah");', it still gets it's
knickers in a twist.

Early versions of IE (<=5?) didn't support Array.push.

Simply create your own push function and add it to Array.prototype to add
this functionalty for any browser that doesn't already have it.
Google it to find examples.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
You're a star Matt! Many thanks for your input. It had never occured to
me that a browser wouldn't support such a basic function.

Nov 30 '06 #3

P: n/a
JohnnySpasm meinte:

[some meaningless IE bashing snipped]

Sorry. Just realised that I responded to a useless reply of a question
from last year.
--
http://www.gregorkofler.at ::: Landschafts- und Reisefotografie
http://www.licht-blick.at ::: Forum für Multivisionsvorträge
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.