Adscend

Click Here



Click Here

Tuesday

Get Browser Information

Browser Information:

Sometimes we need to know the browser’s name, version, etc. The Navigator object is used for this purpose.
Object: Navigator
Method or Function: appName, appVersion
Syntax: Navigator. appName
Syntax: Navigator. appVersion
Syntax: Navigator.platform
appName - holds the name of the browser
appVersion – holds the version of the browser
platform - ?

Example

<script type="text/javascript">
document.write("You are using "+navigator.platform);
document.write("<br />");
document.write("Your browser's name is "+navigator.appName);
document.write("<br />");
document.write("Browser version: "+ navigator.appVersion);
</script>

Output



Math sqrt Function

Math Function sqrt

Syntax
Math.sqrt(x)

1.Math.sqrt(x) takes a number as an argument and returns the square root of that number.

2.The argument is a numeric expression.

3.If a negative number is passed through the argument, for instance Math.sqrt(-9) , the function will return NaN.


Example
<script type="text/javascript">
var n = prompt("Enter a number");
var answer = Math.sqrt(n);
alert("The square root of" +n+ "is" +answer);
</script>




Math Round Function

Math Function Round

Method: Round()
The round() method of the Math object to round a number to the nearest integer.


Example

<script type="text/javascript">
document.write("3.14259 is rounded to " +Math.round(3.14259));
document.write("<br />");
document.write("3.51259 is rounded to " +Math.round(3.51259));
document.write("<br />");
document.write("4.5 is rounded to " +Math.round(4.5));
document.write("<br />");
document.write("4.49 is rounded to " +Math.round(4.49));
document.write("<br />");
document.write("-5.89 is rounded to " +Math.round(-5.89));
document.write("<br />");
document.write("-5.5 is rounded to " +Math.round(-5.5));
</script>

Here ‘Math’ is object and ‘round’ is function.

The browser will show the following:
3.14259 is rounded to 3
3.51259 is rounded to 4
4.5 is rounded to 5
4.49 is rounded to 4
-5.89 is rounded to -6
-5.5 is rounded to -5


Click the buttons below and see what outputs give.










Math Random Function

Math Function Random

Method: Random()
The random() method of the Math object to return a random number between 0 and 1.

Example

<script type="text/javascript">
document.write(Math.random());
</script>






Math Functions Object

Math Object

The Math object allows to perform mathematical tasks.
The Math object includes several mathematical constants and methods.
The mathematical constants that can be accessed from the Math object, there are also several methods available.

Mathematical Constants

JavaScript provides eight mathematical constants. These constants can be accessed from the Math object. These are: E, PI, square root of 2, square root of 1/2, natural log of 2, natural log of 10, base-2 log of E, and base-10 log of E.

Object: Math
Properties: E, PI, sqrt, SQRT2, SQRT1_2, LN2, LN10, LOG2E, LOG10E
Syntax: Math.E
Syntax: Math.PI
Syntax: Math.SQRT2
Syntax: Math.SQRT1_2
Syntax: Math.LN2
Syntax: Math.LN10
Syntax: Math.LOG2E
Syntax: Math.LOG10E





Data Type Convert Integer to String

v)Integer to String

Syntax: parseInt(string, radix)
Object.toString 

Integer value can be converted to string by using the function or method toString(). 


Example

<script language="javascript">
var a = 5;
var b = 6;
var c = a.toString()+b;
document.write(" Converting Integer to String function: "+c);
</script>

Output





Data Type Convert Float to String

iv)Float to String

Syntax: parseFloat(string)

Float value can be converted to string by using the function or method toString() or parseFloat.


Example

<html>
<body>

<script type="text/javascript">

var a = 5.33;
a.toString();
var c = a.toString();
document.write("Float to String is  "+c);
</script>

</body>
</html>

Output





Data Type Convert Float to Int

iii)Float to Integer

Syntax: parseInt(string, radix)
To convert a value from float to integer we have to use the function or method parseInt().

Example

<html>
<head>
</head>
<body>
<script type="text/javascript">
var a = 5.5;
var b = 1;
var c = parseInt(a)+b;
document.write("parseInt(a)+b = "+c);
</script>

</body>
</html>

Output



Click the buttons below and see what outputs give.




Data Type Convert String to Float

ii)String to Float

Syntax: parseFloat(string)

To convert a value from string to float, we have to use the function or method parseFloat(). 
The parseFloat() function parses a string and returns a floating point number.


Example

<html>
<body>

<script type="text/javascript">

document.write(parseFloat ("35.49") + "<br />");
document.write(parseFloat ("35.00000000")+ "<br />");
document.write(parseFloat ("35") + "<br />");
document.write(parseFloat ("0x35")+ "<br />");
document.write(parseFloat ("035")+ "<br />");
document.write(parseFloat ("Hello")+ "<br />");

</script>


</body>
</html>

Output


Click the buttons below and see what outputs give.










Data Type Convert String to Integer

i)String to Integer

Syntax: parseInt(string, radix)

To convert a value from string to integer we have to use the function or method parseInt().

If the string begins with "0x", the radix is 16 (hexadecimal)
If the string begins with "0", the radix is 8 (octal).
If the string begins with any other value, the radix is 10 (decimal)


Example

<html>
<body>

<script type="text/javascript">

document.write(parseInt("35.49") + "<br />");
document.write(parseInt("35.00000000")+ "<br />");
document.write(parseInt("35") + "<br />");
document.write(parseInt("0x35")+ "<br />");
document.write(parseInt("035")+ "<br />");
document.write(parseInt("Hello")+ "<br />");

</script>


</body>
</html>

Output


Click the buttons below and see what outputs give.










innerHTML Tutorial

innerHTML

Syntax
HTMLElementObject.innerHTML=text
document.getElementById(id name).style.property = new style

Each HTML element has an innerHTML property.
The innerHTML property sets or returns the inner HTML of an element.

Example: 1
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").innerHTML="hahaaa i just got changed";
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click "Change the text".
</div>
<button onclick="changeText();">Change the text</button>
</body>
</html>
Output
I will disappear, if you click "Change the text".


Example: 2
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").innerHTML="hahaaa i just got changed<br><a href='http://google.com'>google</a>";
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click "Change the text".
</div>
<button onclick="changeText();">Change the text</button>
</body>
</html>
Output
I will disappear, if you click "Change the text".


Changing text color.

Example: 3
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").innerHTML="hahaaa i just got changed<br><a href='http://google.com'>google</a>";
test.style.color="blue";
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click "Change the text".
</div>
<button onclick="changeText();">Change the text</button>
</body>
</html>
Output
I will disappear, if you click "Change the text".


Creating box.
Example: 4
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").innerHTML="hahaaa i just got changed<br><a href='http://google.com'>google</a>";
test.style.border= "5px dashed red";
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click "Change the text".
</div>
<button onclick="changeText();">Change the text</button>
</body>
</html>
Output
I will disappear, if you click "Change the text".


Example: 5
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").innerHTML="hahaaa i just got changed<br><a href='http://google.com'>google</a>";
test.style.border= "5px dashed red";
}
function changeBack()
{
document.getElementById("test").innerHTML="I will disappear, if you click Change the text.";
test.style.border= "0px";
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click Change the text.
</div>
<button onclick="changeText();">Change the text</button>
<button onclick="changeBack();">Change the text[Back]</button>
</body>
</html>
Output
I will disappear, if you click Change the text.


Example: 6
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").innerHTML="hahaaa i just got changed<br><a href='http://google.com'>google</a>";
test.style.border= "5px dashed red";
}

function changeBack()
{
document.getElementById("test").innerHTML="I will disappear, if you click Change the text.";
test.style.border= "0px";
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click Change the text.
</div>
<button onclick="changeText();">Change the text</button>
<button onclick="changeBack();">Change the text[Back]</button>
</body>
</html>
Output
I will disappear, if you click Change the text.


Example: 7
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById("thelink").innerHTML="Aspell";
thelink.href="http://aspell.org";
}
</script>
</head>
<body>
<div id="test">
<a href="http://google.com" id="thelink">google</a>
</div>
<button onclick="changeLink();">Change the link</button>
</body>
</html>
Output




Click Event getElementById

getElementById

1.getElementById is a method or function of the document object.

2.getElementById can be accessed by using document.getElementById.


Syntax
document.getElementById(id name).style.property = new style

Example: 1
<html>
<head>
<script type="text/javascript">
function changeText()
{
document.getElementById("test").style.color="red";
}
</script>
</head>
<body>
<div id="test">
I will change color, if you click "Change the text".
</div>
<button onclick="changeText();">Change the text</button>
</body>
</html>
Output
I will change color, if you click "Change the text".


Example: 2
<html>
<head>
<script type="text/javascript">
function visible()
{
document.getElementById("test").style.visibility='visible';
}
function invisible()
{
document.getElementById("test").style.visibility='hidden';
}
</script>
</head>
<body>
<div id="test">
I will disappear, if you click Change the text.
</div>
<button onclick="visible();">Click me to show</button>
<button onclick="invisible();">Click me to hidden</button>
</body>
</html>
Output
I will disappear, if you click Change the text.




DOM Tutorial

DOM Tutorial

1.DOM allows to change the values of your CSS properties at runtime.

2.DOM allows to change both the inline and external style sheets.


Syntax:
document.getElementById(id name).style.property = new style
document.getElementById("id").style.property="value";




String Function substring

String Function substring()

Object: String
Method or Function: substring(int, int)
Syntax: String.substring(int, int)

substring function takes two integer arguments. The first argument is the start index and the second argument is the end index.


Example

<script language=javascript>
var x = "Hello Everybody ";
document.write(x.substring(0,7));
</script>


Note:Here string is counted from zero.




String Function split

String Function split()

Object: String
Method or Function: split(argument)
Syntax: String.split(arg)

Split function takes one argument called delimiter.
Every part of the string that comes in between the delimiter is separated as a string.
A delimiter can be any string or a character or even blank space.

Split() method converts any string to "lower" case letter.

Example: 1

<script type="text/javascript">
var a = "split-function-test";
document.write(a.split("-"));
</script>

Here we pass delimiter argument as ‘-‘ sign.


Example: 2

<script type="text/javascript">
var a = "split+function+test";
document.write(a.split("+"));
</script>

Here we pass delimiter argument as ‘+’ sign.


Example: 3

<script type="text/javascript">
var a = "split function test";
document.write(a.split(" "));
</script>

Here we pass delimiter argument as blank space.





String Function length

String Function length()

Object: String
Method or Function: length
Syntax: String.length()

Length method calculates the total no of characters of string and returns the value to a variable.


Example

<script type="text/javascript">
var x = "Hello everybody";
document.write(x.length);
</script>




String Function lastIndexOf

String Function lastIndexOf()

Object: String
Method or Function: lastIndexof(String)
Syntax:String. indexof(String)

lastIndexof function takes a character or string as an argument and finds the position of a character or word in a string and returns the last occurrence position of the string.


Example

<script type="text/javascript">
var string="hello everybody, my name is Aspell";
document.write(string.lastIndexOf("e"));
</script>




String Function IndexOf()

String Function IndexOf()

Object: String
Method or Function: indexof(String)
Syntax: String. indexof(String)

Indexof function finds the position of a character or word in a string.
Indexof function takes a character or string as an argument and searches the given string in the main string and returns the index or starting (first occurrence) position of the string.
If the Indexof function returns -1 ,it indicates that the searching string or character is not present in the main string.


Example

<script type="text/javascript">
var string="hello everybody, my name is Aspell";
document.write(string.indexOf("everybody"));
</script>


Note: ‘everybody’ starts on the 6th letter of the string and computer language start counting from zero.
If we write,
document.write(string.indexOf("Aspell"));
The browser will show the following:
28
If we write ‘joe’, that not exist in the string, browser will return a negative number.
document.write(string.indexOf("joe"));
The browser will show the following:
-1
-1 indicates that ,there is no value or name like “joe” and this is false.



String Function charAt()

String Function charAt()

Object: String
Method or Function: charAt(int)
Syntax: String.charAt(int)

This method takes an integer value as an argument and returns the character of the position of that variable. The position of the string starts from zero(0).


Example

<script type="text/javascript">
var x = "This is a charAt() example";
var y = x.charAt(8);
document.write(y);
</script>




String Function Case Conversion

String Function Case Conversion

Object: String
Method or Function: toUpperCase(), toLowerCase()
Syntax:String.toUpperCase()
Syntax:String.toLowerCase()

We can convert a string to lower case or upper case in JavaScript.
toUpperCase() method converts any string to "UPPER" case letters.
toLowerCase() method converts any string to "lower" case letters.


Converting to Upper Case:

Example: 1

<script type="text/javascript">
var x = " This is a upper case text ";
document.write(x.toUpperCase());
</script>


Converting to Lower Case:

Example: 2

<script type="text/javascript">
var x = " This is a lower case text ";
var y = x.toLowerCase();
document.write(y);
</script>




String Function replace Tutorial

String Function replace()

Object: String
Method or Function: replace(arg1, agr2)
Syntax: string.replace(arg1, agr2)

The replace() function searches for a match in a string, and replaces the matched substring with a new substring.
The replace() function takes two parameters.
The first argument is what we are looking or searching for, and the second argument is what we will replace the found ones with.


Example: 1

<script type="text/javascript">
var string="hello everybody, my name is Aspell";
document.write(string.replace(/Aspell/,"Sky"));
</script>


Example: 2

<script type="text/javascript">
var string="hello everybody, my name is Aspell";
document.write(string.replace("Aspell","Sky"));
</script>


You can also perform a case-insensitive search:

Example: 3

<script type="text/javascript">
var string="hello everybody, my name is Aspell";
document.write(string.replace(/aspell/i,"Sky"));
</script>


You can also perform global, case-insensitive search:

Example: 4

<script type="text/javascript">
var string="hello everybody, my name is Aspell.";
string=string + " Again I say, my name is Aspell.";
document.write(string.replace(/aspell/gi,"Sky"));
</script>




String Function match()

String Function match()

Object: String
Method or Function: match(arg)
Syntax: string.match(arg)

The match() method is used on a string variable or literal, and takes a regular expression pattern as argument to retrieve the matches when matching that string against that regular expression.
If matches were found in the string, the match() method returns an array containing all matched substrings , or null if no match is found.


Example

<script type="text/javascript">
var string="hello everybody,my name is Aspell";
document.write(string.match("Aspell"));
</script>


If we write,
document.write(string.match("Aspelll"));

Output

null

If we write,
document.write(string.match("sky"));

Output

null




Switch Statement Tutorial

Switch Statement

The Switch statement in PHP is used to perform one of several different actions based on one of several different conditions.
Switch case is used to when a condition may have multiple results.
If you want to select one of many blocks of code to be executed, use the Switch statement.
Switch statement is similar to if..else if..else  statement.
The switch statement is used to avoid long blocks of if..else if..else code.


Syntax
switch (expression)
{
case label1:
  code to be executed if expression = label1;
  break;  
case label2:
  code to be executed if expression = label2;
  break;
default:
  code to be executed
  if expression is different 
  from both label1 and label2; 

}

How it works
1. The value of the expression is compared with the values for each case in the structure .
2. If there is a match, the code associated with that case is executed.
3. After a code is executed, break is used to stop the code from running into the next case.
break means, if there is one statement executes, then there is no need to go rest of case statement.
4. The default statement is used if none of the cases are true.
Last case is always default. This is similar to the last else statement.
If none of the above conditions are true, then default will execute.


Example

<script type="text/javascript">
for(var i=1; i<=5; i++)
{
switch(i)
{
case 1:
document.write("when i=1 then case 1 executes <br />");
break;
case 2:
document.write("when i=2 then case 2 executes <br />");
break;
case 3:
document.write("when i=3 then case 3 executes <br />");
break;
default:
document.write("When i=4 then Dedault executes <br />");
break;
}
}
</script>

Output

when i=1 then case 1 executes
when i=2 then case 2 executes
when i=3 then case 3 executes
When i=4 then Dedault executes


Function Parameter Types

Parameters In Functions

Syntax

Function Function_Name([arg1 [, arg2 [, ... argN ]],]){
Function_Body
}


You can pass arguments to a function.
Parameters helps to pass informations/ arguments into the function.
The arguments can be either numbers or strings.
Output of the function depends on the arguments you give it.


Passing String
Passing Integer

Passing String

Example: 1

<html>
<head>
<script language="javascript">
function alertMe(string)
{
alert(string)
}
</script>
</head>

<body onload="alertMe('hi everybody,here I use parameter in function to pass argument')">
</body>
</html>



Example: 2

<html>
<head>
<script language="javascript">

function alertMe(string)
{
alert(string)
}
</script>
</head>

<body onload="alertMe(' hi everybody,here I use parameter in function to
pass argument ')" onunload="alertMe('Good bye,have a nice day')";>
</body>
</html>

When you click “cross button” of the browser, not dialog box, the following alert box will appear in your browser:


Passing Integer

Example: 1

<script type="text/javascript">
function add(a,b)
{
x=a+b;
return x;
}
alert(add(3,4));
</script>


Example: 2

<script type="text/javascript">
function add(a,b)
{
x=a+b;
return x;
}
alert(add(3,4));
alert(add(95,5));
</script>




Function Declaration


Functions



1. A function is a block of statements that perform a specific task of same kind.
2. A function has a name and it is reusable.
3. A function invoked from other parts of a program.
4. A function may have return value or not.
5. A function may have parameters or not.
6. The statements inside the function will not be executed automatically.
7. The function is called from any part of the program and then execute the statements inside the function.
8.When a program calls a function, program control is transferred to the called function.
A called function returns control to the caller when its return statement is executed or when function’s ending closing brace is reached.

Syntax:
returnValueType function_name(parameter-list)
{
// statements that will be executed
}

Example: 1
<script type="text/javascript ">
function hello()
{
alert("This text is in function hello");
}
hello();
</script>


Example: 2
<script type="text/javascript ">
function hello()
{
alert("This text is in function hello");
}
hello();
alert("This text is not in function hello");
</script>


Example: 3
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This is my first java script function")
}
</script>
</head>
<body>
<input type="button" value="Click here to display the message"
onclick="message()">
</form>
</body>
</html>
Output



Example: 4
<html>
<head>
<script language="javascript">

function alertMe()
{
alert("hello everybody !")
}
</script>
</head>

<body onload="alertMe()">
</body>
</html>
The browser will show the following :


When browser will open first time, the above dialog box will display.






Monday

Array Associative

Associative Array

Associative array = Associative word with another word.

In the script below, we create the basis for a Acronym Lookup program in JavaScript. We will use an associative array to reference the meaning of each acronym, and use the acronym as the associative array's index:


We have three associative arrays: MPLS (links the Multi-Protocol Label Switching), SSTP (links the Secure Socket Tunneling Protocol), and LDAP (links the Lightweight Directory Access Protocol).


Example: 1

<script type="text/javascript">
var Protocols = new Array();
Protocols["MPLS"]="Multi-Protocol Label Switching";
Protocols["SSTP"]="Secure Socket Tunneling Protocol";
Protocols["LDAP"]="Lightweight Directory Access Protocol";

document.write("MPLS stands for: " +Protocols["MPLS"]+"<br>");
document.write("SSTP stands for: " +Protocols["SSTP"]+"<br>");
document.write("LDAP stands for: " +Protocols["LDAP"]+"<br>");

</script>

Output




Array Push Method

Array Push

Object: Array_name
Method or Function: push(arg)
Syntax: Array_name. push(arg)


Push method add elements end of the array.

We have month array which contains first six months. We want another last six month to join or append to the existing month array.


Example

<script type="text/javascript">
var month = new Array("January" , "February", "March", "April", "May", "June");


month.push("July", "August", "September", "October", "November", "December");
var string = month.join();
document.write(string);
</script>

Output

January,February,March,April,May,June,July,August,September,October,November, December





Reverse Array Elements

Reverse Array Elements

Object: Array_name
Method or Function: reverse
Syntax: Array_name.reverse()


If we want to reverse entire array elements, we can use the reverse function.


Example

<script type="text/javascript">
var month = new Array("January","February", "March", "April", "May", "June", "July","August", "September", "October", "November", "December");

var string=month.reverse();
document.write(string);
</script>

Output




Array POP Remove Element

Remove last element from Array(POP)

Object: Array
Method or Function
: pop
Syntax: array_name.pop()


The pop() method removes the last element of anarray.

We have four elements in this array.

Example: 1

<script type="text/javascript">
var names=new Array("One" , "Two", "Three", "Four");
for(i=0;i<names.length;i++)
{
document.write(names[i]+ "<br>");
}
</script>

Output

From the output we see that last element is Four.
We want to remove Four.
Lets see the following example:

Example: 2

<script type="text/javascript">
var names=new Array("One" , "Two", "Three", "Four");
for(i=0;i<names.length;i++)
{
document.write(names[i]+ "<br>");
}
names.pop(); //Now our names array contains three elements.
document.write("Now we will not see last element <br><br>");
for(i=0;i<names.length;i++)
{
document.write(names[i]+ "<br>");
}
</script>

Output

The pop() method also returns the element which is poped or removed.


Example: 3

<script type="text/javascript">
var names=new Array("One" , "Two", "Three", "Four");
document.write(names.pop() + "<br>");
</script>
Output

Here we see that element "Four" is returned.





Array Sort Function

Sort Of an Array

Object: Array_name
Method or Function: sort()
Syntax: Array_name.sort()


The sort method sorts array elements either alphabetic or numeric, and either ascending or descending.
Sort method changes the original array.
When nothing is passed to the sort method, every value is converted to a string and sorted in lexicographic order.


We have twelve months, January through December in array month.
We will sort these twelve months alphabetically.


Example

<script type="text/javascript">

var month = new Array("January" , "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December");


var string = month.sort();


document.write(string);
</script>

Output

April,August,December,February,January,July,June,March,May,
November,October,September





Length Of Array

Length Of Array

Object: Array
Property: length
Syntax: array_name.length


An array's length property returns the number of elements in an array.
We can find the length or size of any JavaScript array by using its length property. 


Example

<script type="text/javascript">
var names=new Array("Nora " , "Natalie", "Nicole");

document.write(names.length);

</script>

Click the buttons below and see what outputs give.

Here we see that names array has three elements.





Array Concat Element Method

Add two array elements

Object: Array
Method or Function
: concat(argument)
Syntax: array1.concat(array2,array3,...,arrayn)


concat() method takes two or more array elements and adds them to the end of array.
Useing the concat() method, returns a copy of an original string and the string passed by argument.
The concat() method does not modify the original string, and only a copy of the result is returned.


Example: 1

<script type="text/javascript">

         var month1 = new Array("January" , "February", "March", "April", "May", "June");
         var month2 = new Array("July", "August", "September", "October", "November", "December");

         var months=month1.concat(month2);

        document.write(months);

</script>

Output

January,February,March,April,May,June,July,August,September,
October,November,December



Another way to display array

Example: 2

 <script type="text/javascript">
        var month1 = new Array("January" , "February", "March", "April", "May", "June");
        var month2 = new Array("July", "August", "September", "October", "November", "December");

         var months=month1.concat(month2);

       for(i=0; i<months.length; i++)
        {
         document.write(months[i] + "<br>");
         }
</script>

Output

Here "month1" and "month2" are two arrays and "months" is another array that contains now the elements of "month1" and "month2" arrays.
We could use var months=month2.concat(month1);.
In this case, the order of elements will change.



Print Array Elements

Print Array Elements

In the JavaScript array, we can store multiple values and also can print them wherever we wish.
To access an element in the array, use the variable which is assigned it to, followed by the element's index number inside square brackets ([]).
We can print array elements through loops.

We have 12 variables. We will display these 12 variables through loop.

Example: 1

<script type="text/javascript">
var month = new Array("January" , "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
for(i=0; i<month.length; i++)
{
document.write(month[i] + "<br>");
}
</script>
Output


Example: 2

<script type="text/javascript">
var names=new Array();
names[0]="Robert";
names[1]="palash";
names[2]="mike";
for (i = 0; i < names.length; i++) {
document.write(names[i] + '<br />');
}
</script>
Output


Note: <br /> can be use in single quote or double quotes.