es6 复制对象

var pp = {'name': '1','work': 'teacher'}
var kk = [1,2]
var tt = []
for(let index = 0; index<kk.length;index++) {
    tt.push({...pp})
}
for(let index = 0; index<kk.length;index++) {
    tt[index].age = kk[index]
}
console.log(tt)


  1. tt(2) [{…}, {…}]
    1. 0:{name: "1", work: "teacher", age: 1}
    2. 1:{name: "1", work: "teacher", age: 2}
    3. length:2
    4. __proto__:Array(0)
 

 

posted @ 2018-05-29 20:28  happynood  阅读(639)  评论(0编辑  收藏  举报