I’m doing a getter in VueX, and when i’m returning an object for another function, i have “undefined”.
JavaScript
x
6
1
getId: (state) => (LotofID, id) => {
2
LotofID.points.map(obj => {
3
if (obj.id === id)
4
return (obj);
5
})
6
Basically i have a function like that. When i’m showing obj
with console.log(obj), i have an object with elements in here. And basically it’s working. But when i’m doing a return
and i’m trying to get the obj in another function
JavaScript
1
6
1
var test = []
2
selectedRowKeys.map(obj => {
3
test.push(this.$store.getters.getId(LotofID, obj))
4
})
5
console.log(test)
6
I have a “undefined” in my variable. Anyone have an idea of where the problem can be
Advertisement
Answer
You should use find
method instead of map
and return the found item inside your getter:
JavaScript
1
4
1
getId: (state) => (LotofID, id) => {
2
return LotofID.points.find(obj => obj.id === id)
3
}
4