<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>拷贝数组</title>
<script>
var a = [1,"yes",3];
/*
//方法一,数组的遍历
var b = new Array();
for(var i = 1;i <= a.length;i++){
b.push(a[i]);
}
console.log(b);*/
/*
//方法二,连接concat
var b = [].concat(a);
console.log(b);*/
//方法三,slice
var b = a.slice(0);
console.log(b);
</script>
</head>
<body>
</body>
</html>
前端面试——实现数组的复制
最新推荐文章于 2023-08-06 16:00:58 发布