How to get the last element of an array and remove it from the array in JavaScript?

var arr = [1,2,3,4]; 

I need to get the last one and then remove it from an array named arr :

 var arr = [1,2,3] 
+4
source share
1 answer

You want to do exactly what pop does:

 var arr = [1,2,3,4]; //... var last = arr.pop(); // returns 4, and arr will contain now [1, 2, 3] 
+10
source

Source: https://habr.com/ru/post/1299547/


All Articles