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>

  • 相关阅读:
    [转]maven插件的开发
    开发建议
    [转]利用maven的surefire插件实现单元测试与集成测试
    sonar-maven-plugin错误2
    20145218张晓涵_网络欺诈技术防范
    20145218张晓涵_信息搜集与漏洞扫描
    20145218张晓涵_Exp5 MSF基础应用
    20145218张晓涵 PC平台逆向破解_advanced
    20145218张晓涵 恶意代码分析
    20145218 免杀原理与实践
  • 原文地址:https://www.cnblogs.com/cxx328/p/12719362.html
Copyright © 2011-2022 走看看