Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Array.push(). Doesn't work.

Posted on 1998-08-12
2
Medium Priority
?
200 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 160 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

610 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