Pop() element in JS

Liujiayi_ 2022-06-23 15:11:24 阅读数:662

popelementjs

pop()
- This method can delete the last element of the array , And return the deleted element as the return value
 

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

Return value : 

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

 

 

 

版权声明:本文为[Liujiayi_]所创,转载请带上原文链接,感谢。 https://qdmana.com/2022/174/202206231424014418.html