<script>
var bigShotList = [
{ payAmount: 80000, tel: "158****6871", isMy: "2" },
{ payAmount: 10000, tel: "136****5432", isMy: "2" },
{ payAmount: 4791.37, tel: "136****1118", isMy: "2" },
{ payAmount: 2000, tel: "136****0096", isMy: "2" },
{ payAmount: 1500, tel: "136****0118", isMy: "2" },
{ payAmount: 1000, tel: "136****4357", isMy: "2" },
{ payAmount: 800, tel: "136****4350", isMy: "2" },
{ payAmount: 500, tel: "136****1144", isMy: "2" },
{ payAmount: 500, tel: "136****1119", isMy: "2" },
{ payAmount: 200, tel: "136****4327", isMy: "2" }
]
var addlist = { payAmount: 500, tel: "000****0000", isMy: "添加的数据" }
var row = "";
for (var i = 0; i < bigShotList.length; i++) {
if (addlist.payAmount >= bigShotList[i].payAmount) {
row = i;
break
} else {
row = bigShotList.length;
}
}
console.log('插入位置'+row)
bigShotList.splice(row, 0, addlist)
console.log(bigShotList)
结果:------------
</script>