How to get and remove the last item in an array in JavaScript

1 Answer

0 votes
let arr = [1, 2, 3, 4, 5, 6, 7];
 
let lastitem = arr.pop();
 
console.log(lastitem);
console.log(arr);

 
 
   
     
/*
run:
     
7
[1, 2, 3, 4, 5, 6]
     
*/

 



answered Jan 31, 2021 by avibootz

Related questions

...