0

I do not understand why I am getting undefined.
Is it something about the event loop?
I have tried the following code:

var v = { s: '92', t: '212', h: '33' }
var c=['s','t']
for (var x = 0; x < 3; x++){
    var key=c[x]
    console.log(v.key) 
} 

Result:

undefined

Why this is undefined ?
I have also tried this:

var v = { s: '92', t: '212', h: '33' }
var c=['s','t']
for (var x = 0; x < 3; x++){
    var key=c[x]
    console.log(v.[key])  
} 

I need to access the v object with the key variable, not the key property.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Anand Jha
  • 11
  • 1

0 Answers0