2👍
✅
((groupData.filter(group => (group.id === parseInt(text, 0))))[0].categoryName)||'No Group'
Based on your expression I can highlight few problems:
- Second argument in parseInt is radix and it has to be between 2 and 36, in your code it’s 0 which is incorrect. I assume it has to be 10 because I think id stored in decimal numeral system.
- If any item in your groupData does not match you will get empty array in such case first item in array is
undefined
, and that’s why you get such issue. - Instead of filter I would recommend you to use find, it has same syntax but it returns first matched result or undefined if there is no match.
Something like this:
groupData.find(group => group.id === parseInt(text, 10))
- Don’t write such logic inside template part, it’s not always obvious and hard to debug.
I hope it helps to you.
Source:stackexchange.com