示例代码

<!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>

第二个参数为负值时,从数组的尾部选取元素。

相关文章:

  • 2022-01-11
  • 2021-07-31
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2021-11-09
  • 2021-10-27
相关资源
相似解决方案