코드를 덜 넌센스로 넣으십시오.
<body> <div> sort ()는 배열을 정렬하고 새 메모리를 열지 않으며 원래 배열 요소를 대체합니다 </div> <div id = "showbox"> 1. 간단한 배열 간단한 정렬 <script type = "text/javaScript"> var arrsimple = new Array (1,8,7,6); arrsimple.sort (); document.writeln (arrsimple.join ()); </script> </div> <div> 2. 간단한 배열 사용자 정의 정렬 <script type = "text/javaScript"> var arrsimple2 = 새 배열 (1,8,7,6); arrsimple2.sort (function (a, b) {return ba}); document.writeln (arrsimple2.join ()); </script> 설명 : a, b는 배열의 두 요소를 나타냅니다. reutrn <0 a 이전 b; A = B가 있으면 브라우저 호환성이 단순화됩니다. AB 출력은 작은 것에서 큰 것으로 정렬되고 BA 출력은 큰에서 작은 것으로 정렬됩니다. </div> <div> 3. 간단한 개체 목록 사용자 정의 속성 정렬 <script type = "text/javaScript"> var ObjectList = new Array (); 기능 페르연 (이름, 나이) {this.name = 이름; this.age = age; } ObjectList.push (New Persion ( 'Jack', 20)); ObjectList.push (New Persion ( 'Tony', 25)); ObjectList.push (New Persion ( 'Stone', 26)); ObjectList.push (New Persion ( 'Mandy', 23)); // ObjectList.SORT 정렬 (function (a, b) {return a.age-b.age}); for (var i = 0; i <objectList.length; i ++) {docum }. 함수 작업 메이트 (이름, 나이) {this.name = 이름; var _age = Age; this.age = function () {if (! arguments) {_age = arguments [0];} else {return _age;}}} ObjectList2.push (새 Workmate ( 'Jack', 20)); ObjectList2.push (New Workmate ( 'Tony', 25)); ObjectList2.push (New Workmate ( 'Stone', 26)); ObjectList2.push (New Workmate ( 'Mandy', 23)); // 어린 시절부터 큰 ObjectList2.sort까지 나이별로 정렬 (function (a, b) {return a.age () -B.age ();}); for (var i = 0; i <objectList2.length; i ++) {docum } </script> </div> </body>위의 기사는 일종의 JS 배열에 대한 심층적 인 이해는 내가 공유하는 모든 컨텐츠입니다. 나는 그것이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.