You are on page 1of 2

Array Object:

Example: 1
Write javascript application to find smallest number in array
<html>
<head>
<title>Title of the document</title>
<script language="javascript">
var i,small
a=new Array(34,45,5,67,785,45,2,1)
document.write("The array elements are ")
for(i=1;i<a.length;i++)
{
document.write(a[i])
document.write(" ")
}
small=a[0]
for(i=1;i<a.length;i++)
{
if(a[i]<small)
{
small=a[i]
}
}
document.write("<br>The smallest number in array is "+small)
</script>
</head>
<body>
</body>
</html>

Output:
The array elements are 45 5 67 785 45 2 1
The smallest number in array is 1
Example: 2
Write javascript application to find smallest number in array
<html>
<head>
<title>Title of the document</title>
<script language="javascript">
var i,large
a=new Array(4,56,64,54,3,5656,453)
document.write("The array elements are ")
for(i=1;i<a.length;i++)
{
document.write(a[i])
document.write(" ")
}
large=a[0]
for(i=1;i<a.length;i++)
{
if(a[i]>large)
{
large=a[i]
}
}
document.write("<br>The largest number in array is "+large)
</script>
</head>
<body>
</body>
</html>

Output:

The array elements are 56 64 54 3 5656 453


The largest number in array is 5656

You might also like