希希莱娜
2019-09-27 16:39
采纳率: 64.3%
浏览 1.5k

如何用js将数组中的数据补全

如开始时间为5:00,结束时间为24:00,将传过来的数组
timeArray:['6:05','6:15','6:20','6:25','6:40','6:45','6:55','7:00','8:00','9:00'],
inStation:[10,20,50,60,40,70,50,80,20,10],
outStation:[30,40,35,65,0,40,20,30,10,20]
补成timeArray:
['5:00','5:05','5:10',5:15'',····'6:05','6:10',6:15','6:20','6:25','6:30','6:35',6:40','6:45','6:50','6:55','7:00','7:05',········'8:00',········'24:00'],
inStation:[0,0,········10,0,20,50,60,40,70,50,80,20,10],
outStation:[0,0,········30,40,35,65,0,40,20,30,10,20]
多出的时间间隔将数值补0

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • renkai721 2019-09-27 17:11
    已采纳

    下面给你一段JS,你自己看看

    function printTime() {
        // 不知道你timeArray需要干什么
        // var timeArray = new Array('6:05','6:15','6:20','6:25','6:40','6:45','6:55','7:00','8:00','9:00');
        var time = "";
        for (var i = 5; i <= 23; i++) {
            for (var j = 0; j < 12; j++) {
                var min = "";
                if (j <= 1) {
                    min = "0";
                }
                time = i + ":" + min + (j * 5);
                console.log(time);
            }
        }
        time = "24:00";
        console.log(time);
    }
    
    
    点赞 打赏 评论
  • JonathanYan 2019-09-27 16:50

    不用补,直接输出这个数组不就成了

    点赞 打赏 评论
  • 学习的态度 2019-09-27 17:04

    直接重新生成一个数组比补数组方便多了

    点赞 打赏 评论

相关推荐 更多相似问题