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>
绝地无双
森栏
相关分类