Get the App
SLTechnology News&Howtos  ›  Development  › 

How does javascript delete the first and last elements of an array

Shulou Source: shulou.com Published: 2022-06-03 17:31:15 11月13日 Update

This article mainly explains "javascript how to delete the beginning and end elements of the array", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "javascript how to delete the first and last elements of the array" bar!

Description

1. The shift () method is used to remove the first element of the array and return the value of the first element. This method changes the length of the array!

2. The pop () method deletes the last element of the array and returns the deleted element.

Example

Var arr = new Array (3); arr [0] = "one"; arr [1] = "two"; arr [2] = "three"; console.log (arr); var arrly=arr.shift (); console.log (arrly); console.log (arr) Thank you for your reading, the above is the content of "javascript how to delete the beginning and end elements of the array". After the study of this article, I believe you have a deeper understanding of how javascript deletes the beginning and end elements of the array, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Elements arrays head and tail methods learning content examples that is ideas situations articles more knowledge knowledge points articles follow length problems practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL macOS Huawei vpn