</pre><pre name="code" class="html"><!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> var arr = [{name: "11", age: 25}, {name: "12", age: 24}, {name: "11", age: 26},{name: "11", age: 23}]; var min; for(var i=0;i<arr.length;i++){ for(var j = 0;j<arr.length;j++){ if(arr[i].name==arr[j].name){ if(parseInt(arr[i].age)<parseInt(arr[j].age)){ min=arr[i]; arr[i]=arr[j]; arr[j]=min; } }else if(arr[i].name<arr[j].name){ min=arr[i]; arr[i]=arr[j]; arr[j]=min; } } } for(var i=0;i<arr.length;i++){ console.log(arr[i].name+","+arr[i].age); } </script> </head> <body> 按F12 控制台打印:(IE11) 11,23 11,25 11,26 12,24 </body> </html>
原文地址:http://blog.csdn.net/liuzhijun1989/article/details/37932289