Vue js Array Pop function
Vue js Pop Function: The pop() method in Vue JS removes the final element from an array and returns it. This technique modifies the array's length. We'll go over how to use native JavaScript arrays in this tutorial. A element of an array is removed using the pop function.

written

reviewed

updated

Thanks for your feedback!
Your contributions will help us to improve service.
Delete item from end of the Array In Vue Js.
To Remove last element from array in Vue.js use native javascript pop() function.
Vue js Remove element last index of Array | Example
Copied to Clipboard
xxxxxxxxxx
<div id="app">
<button @click="myFunction">Delete last Element </button>
<p>Countries : {{countries}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
countries:['India','England','America','Australia','China','Russia'],
}
},
methods:{
myFunction(){
this.results = this.countries.pop();
},
}
}).mount('#app')
</script>
Output of above example
Get last item in an Array Using Vue Js.
To get the last index item value, use the pop function and store that value in a variable.
Return last element in Vue js | Example
Copied to Clipboard
xxxxxxxxxx
<div id="app">
<button @click="myFunction">Get </button>
<p>{{river}}<p>
<p>Return last Element: {{results}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
river:['Amazon','Mekong','Amur','Volgo','Rhine','Danube'],
}
},
methods:{
myFunction(){
this.results = this.river.pop();
},
}
}).mount('#app')
</script>
Output of above example
Ad