473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Array.push() not working with IE.

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
3 9054
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Randell D. | last post by:
Folks, Here's my problem: I am createing an array in a file using the reslut of some PHP and MySQL processing. An example of my array would be examlpe="example one"; examlpe="example...
8
by: JS | last post by:
I am trying to add an element to an array like this: var ty = ; zz = "ty"; var ab = null; zz+=""; ab = eval(zz); document.write(ab.length);
3
by: Andrew Phillipo | last post by:
In IE5 I am working with a lot of code that uses Array.push() as well as for(var i in myArray) {} Great - so I'm fixing the Array.prototype.push function for browsers without it. That...
21
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
10
by: Danny | last post by:
I am working on a project where I will receive xml documents from clients machines as a byte array. They will use the web browser navigate method to post the data to my ASP.NET page. I then pick up...
3
by: i | last post by:
Hi, I'm working with an array of nodes, numbering roughly in the thousands. Each node has at least one, but up to four, references to another node - North, South, East, or West. I'm trying to...
1
by: bpejman | last post by:
Hi Everyone, I've been reading and searching the web for days trying to figure out how exactly you can access and read a Perl array or hash from within JavaScript. I've been reading that JSON is...
6
by: npankey | last post by:
I've started experimenting with template metaprogramming in a small project of mine. What I'm trying to accomplish is to generate a static array of templated objects that get specialized based on...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.