I want to add an element to an array in my data function inside the Vue instance, from another array that i create in a separate method in my methods object, Here is my code
export default {
data(){
return {
names: ['Obama','kenedy','lincolen','bush']
}
},
methods: {
addItem(){
let funnyPeople = ['Donald Duck','Tom','Jerry','Donald Trump']
funnyPeople.forEach(name => {
this.names.push(name);
})
}
}
}
<template>
<div>
<ul>
<li v-for="name in names">{{ name }}</li>
</ul>
<button @click="addItem">add Item</button>
</div>
</template>
Now, whenever I click on the add item button, it add all the name at once, this obviously is not the behavior that I want, I want to add one name at a time. thanks in advance
forEachthen?