Prithviraj Mitra Prithviraj Mitra - 24 days ago 8
Javascript Question

Remove last item from array

I have the following array.

var arr = [1,0,2];


I would like to remove the last element i.e. 2.

I used
arr.slice(-1);
but it doesn't remove the value.

Answer

Use splice(index,howmany)

arr.splice(-1,1)