JS:pop() Method

The JavaScript<span style="color:#cf2e2e" class="tadv-color"> pop()</span> method is to remove an element from the rear end of the array.

The <span style="color:#cf2e2e" class="tadv-color">pop()</span> method deletes just one element from the array. The element is topmost element of the array.

In this example, we will pop() just one element from the array and store that element in a variable and display the deleted entry.

<script>
  var fruits = ['apple','orange','grapes'];
  var item = fruits.pop()
  console.log(item)
//output is "grapes"
</script>

The script will remove the last element of the array which is “grapes“. It is stored in the variable <span style="color:#cf2e2e" class="tadv-color">item </span>and output to console.

Rate this post