ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## **数组的克隆(深拷贝)的方法** ### 方法一:forEach ~~~ var temp = []; var a = [1,2,3,4,5]; a.forEach(item=>{   temp.push(item) }) console.log(temp) ~~~ ### 方法二:concat ~~~ var a = [1,2,3,4,5] var b = [].concat(a); console.log(b); ~~~ ### 方法三:slice切割数组 ~~~ var a = [1,2,3,4,5]; var b = a.slice(0); console.log(b); ~~~ ### 方法四:...展开语法 ~~~ var a = [1,2,3,4,5]; var b = [...a]; console.log(b); ~~~ ~~~ var a = [1,2,3,4,5]; var temp =[]; temp.push(...a); console.log(temp) ~~~