Remove last element from javascript array

<button onclick="removeLastElement()">Remove Last Element</button>

<p id="demo"></p>

<script>
var courses = ["javascript", "php", "angularjs", "node js","Abc"];
document.getElementById("demo").innerHTML = courses;

function removeLastElement() {
var removed_element = courses.pop();
console.log(removed_element);
document.getElementById("demo").innerHTML = courses;
}
</script>

pop() returns removed element.

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *