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

slice() substr() substring() indexOf() ?

看下我的注释问题:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array对象 </title>
<script type="text/javascript">
   var myarr1= ["我","爱","你"];
   var myarr2="我爱你"
   document.write(myarr1.slice(myarr1.indexOf("爱")).reverse()+"<br/>");
   document.write(myarr1.indexOf("爱")+"<br/>");
   document.write(myarr2.substring("我",3)+"<br/>");
   document.write(myarr2.substr("我",3)+"<br/>");
   document.write(myarr2.slice(-1));
   document.write(myarr1.substring("我",3)+"<br/>");
   document.write(myarr2.substr("我",3)+"<br/>");
   //.substring()  .substr()是针对于字符串;而.indexOf()为什么在字符串和数组中都能用到? .slice()为什么也可用于字符串呢?
   
</script>
</head>
<body>
</body>
</html>


提问者:慕村1994845 2016-10-13 18:56

个回答