Asked 8 years ago
28 Nov 2016
Views 1217
jessica

jessica posted

how to remove last element from array in JavaScript


var element = ['day','mothh','year']



How to remove last element from array in JavaScript so i get removed last element from array and get remaining in return array
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00


var element = ['day','mothh','year'];
element .pop();//will pop


pop() function will remove last from array

shyam

shyam
answered Nov 30 '-1 00:00


var element = ['day','mothh','year'];
 element .splice(element .length-1,1); // remove last


splice(pos,n)
splice remove element from pos index , n number of element from array
ravi

ravi
answered Nov 30 '-1 00:00


var device = array("iphone 5","iphone 6","iphone 7","iphone 8");
var device_revise;
for(i=0;i<device.length-1;i++){
device_revise[]=device[i];
}
Post Answer