Professional Documents
Culture Documents
19 CSS Exp2
19 CSS Exp2
CSS CO5I(B) 19
2. Array sort Method.
CODE
<html>
<h2>Array Sort Methods</h2>
<body>
<script type = "text/javaScript">
var array = new Array();
array = [8,5,9,4,7,6,2,3,1];
document.write("Initial Array:<br>"+array+"<br>");
document.write("<br>Array Sorted in Ascending
order:<br>"+array.sort()+"<br>");
array.sort(function c(a,b){
return b-a;
})
document.write("<br>Array Sorted in Descending order:<br>"+array);
document.write("By 19-Soham Parab")
</script>
</body>
</html>
OUTPUT
CSS CO5I(B) 19
3. Array push, pop, reverse, join, concat method.
CODE
<html>
<h3>Array Operations</h3>
<body>
<script type = text/javaScript>
var array = new Array("AJP","CPP","EST");
document.write("Initial Array: "+array+"<br><br>");
array.push(poppedElement);
document.write("Array after pushing:
"+poppedElement+"<br>"+array+"<br><br>");
</script>
</body>
</html>
CSS CO5I(B) 19
OUTPUT
CSS CO5I(B) 19
• Exercise
1. Define Array.
Ans: An array is a collection of elements of the same type placed in
contiguous memory locations that can be individually referenced by
using an index to a unique identifier.
CSS CO5I(B) 19