I came across this code while trying to learn about Arrays. Although the code is functioning properly, I have a few questions. What does (10)
mean in line
var ascendingArray = new Array(10);
? Also, what exactly is happening with the code employees = employees.concat(newEmployees);
?
<html>
<head>
<title>Array</title>
<script type="text/javascript">
var employees = new Array();
employees[0]='d';
employees[1]='b';
var newEmployees = new Array();
newEmployees[0]='c';
newEmployees[1]='a';
var ascendingArray = new Array(10);
var decendingArray = new Array(10);
document.writeln('<h3>Employee Names:</h3>');
document.writeln('<br>List Of Employee:<br/>');
employees = employees.concat(newEmployees);
for(var i=0; i < employees.length; i++)
{
document.write("<ul><li>"+employees[i] + "</ul>");
}
ascendingArray=employees.sort();
decendingArray=ascendingArray.reverse();
document.writeln('<br>List of Employees in decending order:');
for(var i=0; i< decendingArray.length; i++)
{
document.write("<ul><li>" + decendingArray[i] + "</ul>");
}
</script>
</head>
<body>
</body>
</html>