This is no doubt down to my limited knowledge on the subject, but I can't seem to figure out how to check whether the integer value is already stored on the data property of array type.
I know the property is of the Observer type and it always seem to return false when asked:
this.selected.includes(value)
Here's my complete example - please note I'm actually casting value to Number to ensure that all numbers are emitted as such rather than string.
<script>
export default {
data () {
return {
selected: [],
};
},
methods: {
update (event) {
const value = this.castOption(event.target.value);
if (this.selected.includes(value)) {
this.selected = this.selected.filter(element => element !== value);
} else {
this.selected.push(value);
}
this.$emit('input', this.selected);
},
castOption(value) {
return isNaN(value) ? value : Number(value);
},
},
}
</script>
So what I'm after is a simple way to determine whether the value is already in the selected array.