欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

分享一道关于js数组的面试题

程序员文章站 2022-03-08 22:36:52
分享一道关于js数组的面试题

分享一道关于js数组的面试题

        <!doctype html>
 	<html>
 	<head>
 	<meta charset="utf-8" />
 	<title></title>
 	</head>
 	<body>
 	<script>
 	//完成以下代码段,实现b数组对a数组的拷贝,方法越多越好
 	var a=[1,"yes",3],
 	b;
 	//	1.数组遍历,push
 	// b=new array();
 	// for(var i=0;i<a.length;i++){
 	// b.push(a[i])
 	// }
 	 
 	// 2.concat() 连接两个或多个数组
 	// b=[].concat(a)
 	 
 	// 3.slice()
 	b=a.slice(0)
 	console.log(b)
 	</script>
 	</body>
 	</html>
 
 	<!doctype html>
 	<html>
 	<head>
 	<meta charset="utf-8" />
 	<title></title>
 	</head>
 	<body>
 	<script>
 	//完成以下代码段,实现b数组对a数组的拷贝,方法越多越好
 	var a=[1,"yes",3],
 	b;
 	//	1.数组遍历,push
 	// b=new array();
 	// for(var i=0;i<a.length;i++){
 	// b.push(a[i])
 	// }
 	 
 	// 2.concat() 连接两个或多个数组
 	// b=[].concat(a)
 	 
 	// 3.slice()
 	b=a.slice(0)
 	console.log(b)
 	</script>
 	</body>
 	</html>