示例代码
<!DOCTYPE html>
<html lang="zh"> <head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>js slice方法第二份参数为负数</title>
<style type="text/css">
</style>
</head> <body>
<script type="text/javascript">
let ss = 'abcd'
//输出abc
console.log(ss.slice(0,-1))
//输出ab
console.log(ss.slice(1,-1))
//输出a
console.log(ss.slice(2,-1))
//输出
console.log(ss.slice(3,-1))
</script>
</body> </html>
第二个参数为负值时,从数组的尾部选取元素。