Solved

Array.push(). Doesn't work.

Posted on 1998-08-12
2
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
matthewallum earned 40 total points
ID: 1268194
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
ID: 1268195
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

749 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