0

This javascript function works well for reading values from an object when it is hardcoded.

function showNote(){
document.write(notes.B[1]);
}

But I can't get it to work with a variable. I would like to do something like this, but I get an undefined variable message.

<script>
showNote(B)
</script>

function showNote(y){
console.log(y);
document.write(notes.y[1]);
}
user808996
  • 179
  • 4
  • 15
  • it should be `showNote('B')` and `notes[y][1]`. See the duplicate question for more details. – Barmar Oct 17 '14 at 16:18
  • Another reason it would be failing is that you can't access variable property names using dot notation. You probably want `document.write(notes[y][1])`. – aebabis Oct 17 '14 at 16:19

0 Answers0