<!-- JavaScript:Arrays code snippet 3a. -->
<!-- Create an 'Array' object, call methods using dot notation
and write values to the page -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
/* create a new 'Array' object called 'myArray' */
var myArray = new Array('Potatoes','Rice','Pasta','Yams');
/* sort in dictionary order */
// 'sort()' method sorts the elements of an array into dictionary order
myArray.sort();
/* 'join()' method puts all the elements of an array into a string,
the elements are separated by the specified delimiter */
document.write("The sorted and joined items in my cart are: "+myArray.join('|'));
document.write("<br />");
/* sort in reverse dictionary order */
// 'sort()' method sorts the elements of an array into dictionary order
myArray.sort();
// reverse() method reverses the order of the elements in an array.
myArray.reverse();
/* 'join()' method puts all the elements of an array into a string,
the elements are separated by a specified delimiter */
document.write("The sorted, reversed and joined items in my cart are: "+myArray.join('|'));
// -->
</script>
</body>
</html>