I'm having a problem in this snippet of code and can not solve it at all, every time I run the code and search (Auto Complete of Words), it returns the error Uncaught TypeError: Can not read property 'match' of undefined.
I have already checked here and it is calling json, doing the mapping right, the problem is in this macth, could anyone help me with this, please?
Thankyou!
Errorcodebelow:
functionfindMatches(wordToMatch,brands){returnbrands.filter(place=>{constregex=newRegExp(wordToMatch,'gi');returnplace.codebrand.match(regex)||place.labelbrand.match(regex)});}functiondisplayMatches(){constmatchArray=findMatches(this.value,brands);consthtml=matchArray.map(place=>{constregex=newRegExp(this.value,'gi');constcodebrandName=place.codebrand.replace(regex,'<spanclass="hl">${this.value}</span>');
const labelbrandName = place.labelbrand.replace(regex, '<span class="hl">${this.value}</span>');
return '
<li>
<span class="name"> Código: "${codebrandName}", Marca: ${labelbrandName}</span>
</li>
';
}).join('');
suggestions.innerHTML = html;
}