1.为什么这个j里面赋值是无限嵌套。想不明白,希望大家帮我一下。<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script type="text/javascript"> var a = [1, 2, 3, 4, 5, [1, 2, 3, 4]]; var j = []; function copyarr(obj) { var n = obj instanceof Array; for(var i = 0; i < obj.length; i++) { if(typeof obj[i] == 'object') { j[i]=copyarr(obj[i]); } else { j[i] = obj[i]; } } return j; } copyarr(a); console.log(j) </script> </body></html>
添加回答
举报
0/150
提交
取消