I have code something like this.
new Vue({
el:'#app',
data:{
cars:[
{
name:'',
make:''
}
]
},
methods:{
addToArray(nameOfTheArray){ //here nameOfTheArray is the string "cars"
//so here I have to do something like this
this.cars.push({
name:'',
make:''
})
}
}
})
My question is can I use that argument(nameOfTheArray) to tell in which array I want to push this object. I mean something like this?
this.nameOfTheArray.push({
name:'',
make:''
})
but this doesn't work. is there any way to use that string argument with this keyword??
this[nameOfTheArray].pushaddToArray: function(nameOfTheArray){