我有两个数组,我想两个都加。是否有可能得到这个:


var frist = {
    "2162018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570651.113
        },
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570827.709
        }
    ]
};
var second = {
    "2362018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529574243.613
        }
    ]
};
//and i want my final data array like this
var final_data = {
    "2162018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570651.113
        },
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570827.709
        }
    ],
    "2362018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529574243.613
        }
    ]
};

最佳答案

var frist =
{ '2162018':
    [
      { st_id: '18ds1', status: 'A', today_milli: 1529570651.113 },
      { st_id: '18ds1', status: 'A', today_milli: 1529570827.709 }
    ]
 }

 var second =
 { '2362018':
   [
     { st_id: '18ds1', status: 'A', today_milli: 1529574243.613 }
   ]
 }

let final_data = {...frist,...second}
console.log(final_data)





是的,您可以简单地使用传播语法来组合和构造新对象

10-06 00:49