Skip to content
Advertisement

Javascript splice last element

JavaScript

I want to remove only the last element. Why does it remove every element except the last one?

Advertisement

Answer

You need to omit the assignment.

JavaScript

If you like just to delete the last one, you could take a negative index with Array#splice. This works for any other index from the end.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement