Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Tracey King   on Apr 11 In Java Category.

  
Question Answered By: Anna Hill   on Apr 11

As you probably know, javascript  handles objects in odd ways compared
to java  and other languages. It is possible to have an array  grow
dynamically in Javascript. Here is a code snippit:

<script type="text/javascript" language="JavaScript">
<!-- Hide this script from incompatible browsers!

var stuff = new Array(3)
stuff[1] = "hello"
stuff[2] = 27
stuff[3] = 8.5
stuff[5] = "element number 5"
for( i = 1; i <= 5; i++){
document.writeln("stuff[" + i + "] = " + stuff[i]);
}
-->
------------------------------------------------

Here is the output:

stuff[1] = hello
stuff[2] = 27
stuff[3] = 8.5
stuff[4] = undefined
stuff[5] = element number 5

-------------------------------------------------

Notice that while we define the array as having indices 1 to 3, we
extend it by assigning a value to element number 5.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Javascript Array Or get search suggestion and latest updates.


Tagged: