Blogger Information
Blog 42
fans 5
comment 0
visits 38194
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1217:Javascript数组,增,改,删
张浩刚
Original
847 people have browsed it
  1. <script>
  2. let arr = ['a','b','c','d'];
  3. //push() 在数组尾部新增一个值
  4. function show1(){
  5. arr.push('e');
  6. console.log(arr);
  7. }
  8. show1();
  9. //pop() 去除数组尾部的一个值
  10. function show2(){
  11. arr.pop();
  12. console.log(arr);
  13. }
  14. show2();
  15. //unshift() 在数组第一个位置,新增一个值
  16. function show3(){
  17. arr.unshift('aa');
  18. console.log(arr);
  19. }
  20. show3();
  21. //shift() 去除数组第一个值
  22. function show4(){
  23. arr.shift();
  24. console.log(arr);
  25. }
  26. show4();
  27. //删除数组中某个或多个值 splice(起始位置,长度)
  28. function show5(){
  29. arr.splice(1, 2);
  30. console.log(arr);
  31. }
  32. show5();
  33. </script>
Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!