a.name返回的是name值we,lis...等,但它们怎么能比较大小?但这个排序结果又是跟据什么来排序的呢? <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var users=[ {name:'we',age:22}, {name:'lisi',age:35}, {name:'zs',age:76}, {name:'roswee',age:202}, ]; users.sort(function(a,b){ if(a.name>b.name)return 1; if(a.name<b.name)return -1; return 0; }); for(var i in users){ console.log(users[i]['name']); }; </script> </body> </html>
常山造纸农
相关分类