Solved

Array.push(). Doesn't work.

Posted on 1998-08-12
2
191 Views
Last Modified: 2008-03-10
Browswer: IE 4.0.

I'm trying to use the push() method of object Array. But it doesn't seem to be working in my browser.

I get this error:
 Object doesn't support this property or method.
I went to the debugger and this is the code it was at:
 myFish = ["angel", "clown"];
 document.writeln("myFish before: " + myFish);
 pushed = myFish.push("drum", "lion"); // This line caused the error.
 document.writeln("myFish after: " + myFish);
 document.writeln("pushed this element last: " + pushed);

It should work. Why? Because I got it directly off Netscape's JavaScript Reference page. Is this method supported in my browser? Is there a reason this isn't working?
0
Comment
Question by:TylerRick
2 Comments
 

Accepted Solution

by:
matthewallum earned 40 total points
Comment Utility
IE dosn't support the Nestcape 'push' on to an array.
An easy workaround is for both browsers is;

 theArray[theArray.length] = varToBePushed

From your code it would be something like;

 myFish[myFish.length] = "drum"
 myFish[myFish.length] = "lion"

Hope this helps


 


 


0
 

Author Comment

by:TylerRick
Comment Utility
I think that will work.

What I wanted was a way to add members to an array without using arbitrary index numbers such as:
array[0] = "value";
array[1] = "value";

Looks like your way is just what I needed. Thanks a lot!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now