I'm trying to check if a number is present in an array (which I've done a thousand times before using .indexOf()) but I seem to be missing something now.
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)
}
}
Initially, this.selectedSeats is equal to [], and the first condition runs perfectly. However, when I try to add another seat, I get [Vue warn]: Error in event handler for "showSeat": "TypeError: this.selectedSeats.indexOf(...) is not a function". What am I missing?
seata string or an object?this.selectedSeatsbefore callingindexOfon it will provide a cluethis.selectedSeatsis not an array. What do you get if you doconsole.log(Array.isArray(this.selectedSeats));beforelet index?this.selectedSeats.indexOf(should be a native function). Also, isshowSeatsasynchronous? Maybe some more (but not too much) code for context? A jsfiddle or something?