myarr1.slice(1,3) 里的(1,3)是怎么定义出爱你两个字的?
如题,谢谢:)
2016-03-16
其实3是不必的
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array对象 </title>
<script type="text/javascript">
var myarr1= ["我","爱","你"];
document.write(myarr1.slice(1));
</script>
</head>
<body>
</body>
</html>
这个就可以,start的起始位置是数组里面的第二的数,数组下标是从0开始的,所以说“爱”字的下标是1,
“
myarr1.slice(1,3)其实是给数组又加了一个空元素
”
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array对象 </title>
<script type="text/javascript">
var myarr1= ["我","爱","你"];
document.write(myarr1.slice(1,3)+"<br />");
document.write(myarr1.length)
</script>
</head>
<body>
</body>
</html>
输出:爱,你
3
举报