<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <script> var arr = ["关羽","张飞","刘备"]; var arr2 = [1,2,3] console.log(arr); // //在数组的最末尾添加元素(返回新数组的长度) // var aaa = arr.push("abc"); //// var aaa = arr.push("abc","def"); //// var aaa = arr.push(arr2); // console.log(aaa); // console.log(arr); // // //在数组的最末尾删除一个元素(返回新被删除的元素) // aaa = arr.pop(); // console.log(aaa); // console.log(arr); //unshift在数组的最前面添加元素 aaa = arr.unshift("abc"); console.log(aaa); console.log(arr); aaa = arr.shift(); console.log(aaa); console.log(arr); </script> </body> </html>
时间: 2024-09-28 12:10:37