I am a newcomer to JavaScript and learning now. I am using for/in to print a properties and the value of each property of a object. But I am able to print only the properties but not the property values.
Code snippet:
var obj = {x:1,y:2,z:3}
var disp_obj = function(obj){ for(p in obj) console.log(p, obj.p) }
disp_obj(obj)
And the output is: x undefined y undefined z undefined
As I can see from the output, only the property names are printed but not its values. Please correct me what is wrong with this?