<title>综合练习3-1</title> <script language="javascript"> <!-- // 定义变量引用一个数组对象 var oMyArray = new Array( 13, 55, 37, 33, 45, 9, 60, 21, 10 ); // 输出排序前的数组 document.write( "排序前:" + oMyArray ); // 开始排序 for ( index in oMyArray ) { for ( i in oMyArray ) { if( oMyArray[index]<oMyArray[i] ) { nTemp = oMyArray[index]; oMyArray[index] = oMyArray[i]; oMyArray[i] = nTemp; } } } // 输出排序后的数组 document.write( "<br>排序后:" + oMyArray ); --> </script>
输出:
排序前:13,55,37,33,45,9,60,21,10
排序后:9,10,13,21,33,37,45,55,60
时间: 2024-10-18 10:59:47