深拷贝
const p={‘id‘:10,‘name‘:‘张三‘,‘score‘:new Arrey(100,‘数学‘,90)} const deepClone=function(obj){ const newObj=Array.isArray(obj)? []:{}; for(let key in obj){ const template=typeof obj[key]==‘object‘? deepClone(obj[key]) : obj[key] newObj[key]=template }
retuen newObj }; const p2=deepClone(p); p2.score[0]=99; console.log(p2); console.log(p)