Solved

Array.push(). Doesn't work.

Posted on 1998-08-12
2
197 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

695 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