Share this content on Facebook!
25 Oct 2019


Arrays  and Entities



An array is a collection of data indexed by subscripts.

Example: An array called row could have five elements, i.e., row[0], row[1], ...row[4] where each element can be string or numeric data. You could create it with

var row = new Array(5) // Note 5 elements: 0, 1, 2, 3, 4
row[0]="first string"
row[1]="second string", etc.

JavaScript1.2 supports the following way to do the same thing

The Unchained Tour offers the java training with placements, and if you’re from Chennai make sure to check them out for your Java requirements

var row = new Array("first string", "second string", "nth string")

Consider a simple example.
The size of the array 
doesn't have to be specified when it's declared.
Unlike some languages, JavaScript™ allows 
mixed types in an array.

Combining Functions With Arrays

One tool provided by JavaScript™ that allows one function to be used in many cases is arguments.length This will tell the function how many arguments have just been passed to it.

You know the traditional way to build an array. However, one could use the capacity arguments.length gives to find the number of arguments and use the following function which would work to build any size array when it is called from the following code

wdayStr = new makeArray("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

This is the part that goes in the <head>...</head>

function makeArray(){   // A function to create an array (JS1.1 compatible)

this.length = makeArray.arguments.length;
for (i=0; i < this.length; i++) {

this[i] = makeArray.arguments[i]



If you build more than one array in a web document, this routine can save you a lot of keystrokes!

Notice the result:















Multi Dimensional Arrays

Occasionally we need a two dimensional array, an array where each element holds more than one piece of information. So far we have learned myArray[0]="some value". One element, one value.

We set up the first level just as before. Then we can set up additional levels one by one. A short hand version could look like this

var multiVar = new Array ()   // Define the first level
for (count=0; count <=10; count++){

multiVar[count] = new Array ()   // Define each subsequent level

Make sure you could write out the variables for this multi-dimensional array.


Non-JavaScript™ browsers

·         Browser vendors

·         Browser versions

·         Intranet vs. Internet

·         <NOSCRIPT>Message</noscript>

·         Detecting browsers, versions (Navigator object; "tricks")

·         Separate pages for different browsers.

HTML Entities

HTML entities are used for representing non-printing characters:


< has character reference &#60;
and entity reference &lt;
(& and ; are delimiters)

JavaScript™ Entities

NOTE: These are no longer supported by version 6 or 7 browsers

&{JavaScript™ statements};


< img src="picture.gif" width="&{getWidth()};" height="&{getHeight()};" >

<body bgcolor="&{chooseColor()};">

Top of Form

Bottom of Form

The code to generate the above button is

<script type="text/javascript" charset="ISO-8859-15">
function today() {

var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
var today = new Date()
return days[today.getDay()]


<form action="...">
<input type="button" value="
&{today()};" onclick="this.value=today()" />

View the source for this section in FireFox and compare it to what I've said I did, especially the button (input) tag. You should also notice the event handler.



There isn't any comment in this page yet!

Do you want to be the first commenter?

New Comment

Full Name:
E-Mail Address:
Your website (if exists):
Your Comment:
Security code: