合并多个对象并且去重的2种写法(es6)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>this is es6</h1>
<script>
/*对象去重合并的两种方法*/
let objOne = {a:1};
let objTwo = {b:2};
let objThree = {b:4,c:5};
let obj = Object.assign(objOne,objTwo,objThree);
console.log(obj) // {a:1,b:4,c:5}
let obj1={...objOne,...objTwo,...objThree};
console.log(obj1) // {a:1,b:4,c:5}
</script>
</body>
</html>

posted @ 2019-02-14 10:05  Angel-01  阅读(4356)  评论(0编辑  收藏  举报