0π
β
The find()
callback compares item.id
(a Number
) to selected
(a String
):
var item = this.options.find(item => item.id === this.selected);
^ ^
Number String
Strict equality (===
) compares both type and value. Since the two types are different in this case, the comparison would always be false
, resulting in undefined
being returned from find()
.
One solution is to convert selected
to a Number
, and use that to compare:
var selectedId = Number(this.selected);
var item = this.options.find(item => item.id === selectedId);
Source:stackexchange.com