Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the last item from an array (and not return item)

My current array: abc = ['a', 'b', 'c', 'd'];

I understand .pop() remove and returns the last item of an array, thus: abc.pop(); = 'd'

However, I want to remove the last item, and return the array. So it would return:

['a', 'b', 'c'];

Is there a JavaScript function for this?


1 Answers

pop() function also removes last element from array, so this is what you want(Demo on JSFiddle):

var abc = ['a', 'b', 'c', 'd'];
abc.pop()
alert(abc); // a, b, c
like image 82
Daniel Kmak Avatar answered Sep 17 '25 16:09

Daniel Kmak