主要使用Array对象中的Sort()方法
API-Sort()方法
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p id="demo">单击按钮进行数组排列</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
var points = [{i:10,c:0},{i:9,c:0},{i:1,c:0},{i:5,c:0},{i:25,c:0},{i:10,c:0}];
points.sort(function(o1,o2){return o1.i-o2.i});
var x=document.getElementById("demo");
var text ='';
points.forEach(function(c){
text += JSON.stringify(c);
});
x.innerText = text;
}
</script>