1、简单的数组排序
<script type="text/javascript">
var arrSimple=[1,7,8,6,6]
arrSimple = arrSimple.sort();
console.log(arrSimple);
</script>
2、简单的数组自定义排序
<script type="text/javascript">
var arrSimple=[1,7,8,6,6]
arrSimple = arrSimple.sort(function(a,b){
return b-a});
console.log(arrSimple);
</script>
a-b、表示输出从小到大排序,b-a、表示输出从大到小排序
3、简单的数组对象排序
<script type="text/javascript">
var arrSimple=[
{name: 'jony' , val: '34'},
{name: 'jon' , val: '54'},
{name: 'jo' , val: '24'},
{name: 'j' , val: '14'}
]
arrSimple = arrSimple.sort(function(a,b){
return b.val-a.val});
console.log(arrSimple);
</script>