• js数据封装处理


    var arr = [
        {
            id: "1",
            date: "2018-07-27",
            time: "10:00-12:00",
            schedule: "开幕式"
        },
        {
            id: "2",
            date: "2018-07-27",
            time: "12:00-14:00",
            schedule: "世界杯||今日看点||法国队"
        },
        {
            id: "3",
            date: "2018-07-28",
            time: "10:00-12:00",
            schedule: "奥尼尔"
        }, {
            id: "4",
            date: "2018-07-28",
            time: "15:00-17:00",
            schedule: "阿拉巴||巴西||俄罗斯"
        }
    ]
    
    var obj = {};//重新封装对象
    for (var i = 0; i < arr.length; i++) {
        var item = arr[i];//item
        if (!obj[item['date']]) {
            var _arr = [];
            _arr.push(item);
            obj[item["date"]] = _arr;
        } else {
            obj[item["date"]].push(item);
        }
    }
    console.log(obj)
    //对象的遍历
    for (var key in obj) {
        console.log(obj[key]);
    }
    
    var tab = {aa: 11111};
    //console.log(tab.aa);
    //console.log(tab['aa']);
    

      

  • 相关阅读:
    find the most comfortable road
    Rank of Tetris
    Segment set
    Codeforces Round #380 (Div. 2)D. Sea Battle
    A Bug's Life
    Is It A Tree?
    N皇后问题
    符号三角形
    2016 ICPC总结
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/songjn/p/9383825.html
Copyright © 2020-2023  润新知