GTU WTAD Practical 6 : Write a JavaScript to remove the highest element from the array and arrange the array in ascending order.

GTU WTAD Practical 6 : Write a JavaScript to remove the highest element from the array and arrange the array in ascending order.

GTU WTAD Practical 6

JavaScript Array is most useful for storing multiple elements into Array. Another important functionality how to sort element of Array.  Example shows how to create Array in JavaScript. Here i have also used Random Number generator store some values in Array.

Jump to GTU WTAD Practical 7

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu06\

<html>
<head>
	<title> GTU WTAD Practical 6 : Write a JavaScript to remove the highest element from the array and arrange the array in ascending order. </title>

	<script language="javascript">
			//Creating Array
			a=new Array(5);
			//Generate Random Values for Array
			a[0]=Math.floor(Math.random()*100+1)
			a[1]=Math.floor(Math.random()*100+1)
			a[2]=Math.floor(Math.random()*100+1)
			a[3]=Math.floor(Math.random()*100+1)
			a[4]=Math.floor(Math.random()*100+1)
			
			function gtu_wtad_practical_6()
			{
				document.write("Array Values (Random Generated)"+"<br>")
				for(i in a)
				{
					document.write(a[i]+"<br>")
				}
				for(i in a)
				{
					for(j in a)
					{
						if(a[i]<a[j])
						{
							temp=a[i]
							a[i]=a[j]
							a[j]=temp
						}	
					}
				}
				document.write("Array in ascending order"+"<br>")
				for(i in a)
				{
					document.write(a[i]+"<br>")
				}
				document.write("Removed element"+"<br>")
				document.write(a.pop())
				document.write("<br>")
				document.write("<br>")
				document.write("<br>")
				document.write("New Array"+"<br>")
				for(i in a)
				{
					document.write(a[i]+"<br>")
				}
			}

	</script>
</head>
<body>
	<center> <h2> GTU WTAD Practical 6 : Write a JavaScript to remove the highest element from the array and arrange the array in ascending order.  </h2></center>
	
	<script language="javascript">
		gtu_wtad_practical_6()
	</script>
</body>
</html>

 Output

GTU WTAD Practical 6

 

 

 

Leave a Reply