当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 分享一道关于js数组的面试题

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

2018年10月15日  | 移动技术网IT编程  | 我要评论

分享一道关于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>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网