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>

  • 相关阅读:
    day05 集合
    day05 判断敏感字符
    day05 None类型
    day05 字典
    day04元组
    day04列表
    HDFS配额管理(实战)
    hive数据库的哪些函数操作是否走MR
    oracle 裸设备划分 --centos6.5
    redis3.0.7集群部署手册
  • 原文地址:https://www.cnblogs.com/cxx328/p/12719362.html
Copyright © 2011-2022 走看看