. Advertisement .
..3..
. Advertisement .
..4..
Hi developer experts, I have a small but frustrating use case, and so far, I couldn’t get my head around this problem & ideal solution. I am running my command and facing one problem with the uncaught typeerror: cannot read property ‘0’ of undefined. Below is the command I used:
var words = [];
function addLetter(letter,d){
var ascii = letter.charCodeAt(0)-97;
if(!hasLetter(letter,d)){
document.write("This letter" + letter + " hasn't been found in words.");
d[ascii] = new Node(letter);
}
document.write("This letter " + letter + " already exists in words.");
document.write(d[ascii].letter);
addLetter("a",words);
When I run it, I get the following error:
Uncaught TypeError: Cannot read property '0' of undefined
I am looking forward to gaining some knowledge from all experts. Thank you, guys!
The cause: Instead of sending the array, you are only passing the first word. The uncaught typeerror: cannot read property ‘0’ of undefined appears. The error at:
Solution: As an alternative, give the function the array to fix the issue.
Your code is error-free
But I call the
hasLetter
method as follows: