Here is a part of my object
const category = {
fr: {
list: [
{id: 1, label: 'coucou'},
{id: 2, label: 'moi'},
{id: 3, label: 'ici'},
{id: 4, label: 'maintenant'},
{id: 5, label: 'demain'},
]}}
const lang = fr;
const anyId = 3;
I don't know why when doing the following:
const result = category[lang].list.find(item => item.id === anyId) console.log(result)
Throws the following:
// undefined category[lang].list.find(item => item.id === anyId) is not a function, or just undefined
same result for .map or .filter
console.log(category)returns no errorconsole.log(category[lang])returns no errorconsole.log(category[lang].list)returns no error
but anything else will return an error. It drives me crazy, any help will be highly appreciated.
const lang = 'fr'not lteralfrBy havingfrnot wrapped in quotes your code is expectingfrto have already been defined (hence theundefinederror during run time) :-)is not a function, or just undefined--> so is it the first or the second error? Is it undefined, but defined, just not a function??console.log(category[lang]) returns no error, but what does it display?frwith quotes, but you need to be sure is that what you want. The variablefrhereconst lang = fr;is another declared variable?