Every time I've needed to verify if a number exists in an array, I rely on using .indexOf()
, but for some reason, it's not working this time around.
Vue method
showSeat(seat) {
if( !this.selectedSeats.length ) {
this.selectedSeats.push(seat)
} else {
let index = this.selectedSeats.indexOf(seat)
( index >= 0 ) ? this.selectedSeats.splice(index,1) : this.selectedSeats.push(seat)
}
}
At the start, this.selectedSeats
is an empty array, and the first condition executes as expected. However, upon attempting to insert another seat, I encounter
[Vue warn]: Error in event handler for "showSeat": "TypeError: this.selectedSeats.indexOf(...) is not a function"
. What could be causing this issue?