标签:
var arrA=[1,2,3,4]; var arrB; arrB=arrA;//将arrA的引用赋值给arrB arrB[0]=‘aaa‘; console.log(‘arrA‘,arrA);//[‘aaa‘,2,3,4] console.log(‘arrB‘,arrB);//[‘aaa‘,2,3,4] var arrC=[1,2,3,4]; var arrD; arrD=arrC.slice();//用slice()创建新数组,切断两个数组的联系 arrD[0]=‘ccc‘; console.log(‘arrC‘,arrC);//[1,2,3,4] console.log(‘arrD‘,arrD);//[‘ccc‘,2,3,4] var arrE=[5,6,7,8]; var arrF=[]; arrF.push(arrE);//将arrE的引用push到arrF console.log(‘arrF‘,arrF);//[[‘eee‘,6,7,8]] console.log(‘arrE‘,arrE);//[5,6,7,8] arrE[0]=‘eee‘; console.log(‘arrF‘,arrF);//[[‘eee‘,6,7,8]] console.log(‘arrE‘,arrE);//[‘eee‘,6,7,8]
标签:
原文地址:http://www.cnblogs.com/king2016/p/5766942.html