在js中合并对象
将两个数组合并对象
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="format-detection" content="telephone=no"/>
<title>对象合并</title>
</head>
<body>
<script>
var follow_list_old = {
"09/06": [
{
"follow_id": "298",
"follow_time": "14:20",
"follow_content": "已沟通,老客户,未接通电话,再次购买,无意向,vip客户,抽奖客户,新客户",
"operator": "Gjx"
},
{
"follow_id": "297",
"follow_time": "14:18",
"follow_content": "未接通电话",
"operator": "Gjx"
},
{
"follow_id": "296",
"follow_time": "14:18",
"follow_content": "老客户,抽奖客户",
"operator": "Gjx"
}
],
"08/28": [
{
"follow_id": "111",
"follow_time": "13:45",
"follow_content": "无意向,抽奖客户,已沟通",
"operator": "Gjx"
}
],
"08/27": [
{
"follow_id": "107",
"follow_time": "17:44",
"follow_content": "抽奖客户,新客户",
"operator": "Gjx"
},
{
"follow_id": "104",
"follow_time": "15:38",
"follow_content": "再次购买,已沟通",
"operator": "Gjx"
},
{
"follow_id": "103",
"follow_time": "15:38",
"follow_content": "抽奖客户,已沟通",
"operator": "Gjx"
},
{
"follow_id": "102",
"follow_time": "14:56",
"follow_content": "再次购买,已沟通",
"operator": "Gjx"
},
{
"follow_id": "101",
"follow_time": "14:56",
"follow_content": "已沟通",
"operator": "Gjx"
},
{
"follow_id": "100",
"follow_time": "14:55",
"follow_content": "已沟通",
"operator": "Gjx"
}
]
};
console.log('follow_list_old==', follow_list_old);
var follow_list_new = {
"08/27": [
{
"follow_id": "99",
"follow_time": "14:55",
"follow_content": "ddss",
"operator": "Gjx"
},
{
"follow_id": "98",
"follow_time": "14:55",
"follow_content": "再次购买,已沟通,老客户",
"operator": "Gjx"
},
{
"follow_id": "97",
"follow_time": "14:55",
"follow_content": "再次购买,已沟通",
"operator": "Gjx"
},
{
"follow_id": "96",
"follow_time": "14:53",
"follow_content": "再次购买,已沟通,已沟通,再次购买",
"operator": "Gjx"
},
{
"follow_id": "95",
"follow_time": "14:52",
"follow_content": "已沟通,抽奖客户",
"operator": "Gjx"
},
{
"follow_id": "94",
"follow_time": "14:52",
"follow_content": "已沟通,已沟通",
"operator": "Gjx"
},
{
"follow_id": "93",
"follow_time": "14:51",
"follow_content": "再次购买",
"operator": "Gjx"
},
{
"follow_id": "92",
"follow_time": "14:48",
"follow_content": "再次购买,已沟通,未接通电话",
"operator": "Gjx"
},
{
"follow_id": "91",
"follow_time": "14:48",
"follow_content": "再次购买,已沟通,抽奖客户,再次购买,未接通电话",
"operator": "Gjx"
},
{
"follow_id": "90",
"follow_time": "14:48",
"follow_content": "再次购买,已沟通,老客户,未接通电话",
"operator": "Gjx"
}
]
};
console.log('follow_list_new==', follow_list_new);
for (var key in follow_list_new) {
if (follow_list_new.hasOwnProperty(key) === true) {
//此处hasOwnProperty是判断自有属性,使用 for in 循环遍历对象的属性时,原型链上的所有属性都将被访问会避免原型对象扩展带来的干扰
for (var keya in follow_list_new[key]) {
follow_list_old[key][follow_list_old[key].length] = follow_list_new[key][keya];
}
}
}
console.log('follow_list_old===', follow_list_old);
var obj = {'name' : '奇葩天地网' , 'url' : 'www.qipa250.com' , 'age' : '14'};
console.log(Object.keys(obj));
</script>
</body>
</html>