Developer7
Developer7

Reputation: 9

JavaScript . could not understand why my first console statement gives an undefined

function person(name){

   this.name1 = "His";

   this.day = {};
   this.day.time="kokok";


    this.check = function(name){

    for(var i in this)  console.log(this["i"]);

    if(this.name1===name) console.log("ready"+this.day.time);
     };
 }


 var t= new person("His");
 t.check("His");

Upvotes: 0

Views: 21

Answers (1)

jfriend00
jfriend00

Reputation: 707328

It needs to be:

 console.log(this[i]);

instead of:

 console.log(this["i"]);

You want to reference the variable i, not a string "i".

Upvotes: 1

Related Questions