问答详情
源自:7-21 选定元素slice()

为什么slice(-1)输出的是数组第一个值呢

<!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)+"<br>");

   document.write(myarr1.reverse()+"<br>");

   document.write(myarr1.slice(-1)+"<br>");

</script>

</head>

<body>

</body>

</html>



提问者:慕婉清0208 2018-03-13 20:30

个回答

  • 帆布
    2018-03-13 21:22:25

    myarr1.reverse()已经将数组顺序调换了,这个时候你的myarr1=["你","爱","我"]