当前位置:网站首页>JS中的pop()元素

JS中的pop()元素

2022-06-23 14:24:00 刘家奕_

pop()
-该方法可以删除数组的最后一个元素,并将被删除的元素作为返回值返回
 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      arr = [
        [1, 2, 3],
        [3, 4, 5],
        [5, 6, 7],
      ];
      arr.pop();
      alert(arr);
    </script>
  </body>
</html>

返回值: 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      arr = [
        [1, 2, 3],
        [3, 4, 5],
        [5, 6, 7],
      ];

      var result = arr.pop();
      alert(arr);
      console.log("result=" + result);
    </script>
  </body>
</html>

 

 

 

原网站

版权声明
本文为[刘家奕_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_62387059/article/details/125422276