How javascript array deletes the last element
This article mainly explains "javascript array how to delete the last element", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "javascript array how to delete the last element" bar!
Delete method: 1, use Array's pop () method, syntax "array.pop ()"; 2, use delete operator, syntax "delete arr [arr.length-1]"; 3, use splice () method, syntax "arr.splice (- 1)".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Method 1: use the pop () method-you can delete an element at the end of the array
The array.pop () method deletes the last element in the array array and returns the deleted element.
Let's take a look at the following examples:
Var arr = [2, 4, 6, 8, 10]; / / define the array arr.pop (); console.log (arr)
Method 2: delete the last element of the array using the delete operator
Var arr = [2, 4, 6, 8, 10]; / define the array var len=arr.length;// to calculate the array length delete Arlen [Len-1]; / / delete the last element (array length-1) console.log (arr)
Method 3: use the splice () method
Var arr= [1Jing 2 Jing 3 Jing 4 Jo 5]; / / starting from the penultimate element, intercept two elements arr.splice (- 1 Jol 1); console.log (arr)
Thank you for reading, the above is the content of "how to delete the last element of javascript array", after the study of this article, I believe you have a deeper understanding of how to delete the last element of javascript 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!