zoukankan      html  css  js  c++  java
  • 数组里添加一行数据(splice)

    <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>

  • 相关阅读:
    wireshark 导出所有filter出来的包
    ubuntu 14.04安装pypcap
    激活windows7 企业版小记
    ubuntu 14.04 以root权限启动chrome
    git clone Linux 源码并切换TAG
    ubuntu 14.04 ns2.35 ***buffer overflow detected **: ns terminated解决办法
    我离baidu.com有几跳
    linux tcp超时重传实现分析
    dpctl 工具使用
    由于log太多导致ubuntu硬盘空间满了,进入不了系统解决办法
  • 原文地址:https://www.cnblogs.com/cxx328/p/12719362.html
Copyright © 2011-2022 走看看