I have a simple application where a user selects a value from a dropdown list and when they click on the "add" button that value and its id should be populated into an array using the id as an index.
Example:
Values
1 - Apple
3 - Bananas
8 - Pears
User selects each fruit, clicking add after each selection. My array should look like this:
[
1: Apple,
3: Bananas,
8: Pears
]
However what I end up with in Vue is this:
[
1: Apple,
2: undefined,
3: Bananas,
4: undefined,
5: undefined,
6: undefined,
7: undefined,
8: Pears
]
These values are being passed as input to server validation and obviously this is creating a problem with array length and validation rules. How can I remove these undefined values or prevent Vue from populating them in the first place?