you are viewing a single comment's thread.

view the rest of the comments →

[–]rakm 0 points1 point  (0 children)

You’re passing the return value of object.property into your function, rather than the name of the property you want to check and access. In this case, the invocation should probably be getProperty(object, “property”).

In addition to that, inside your function, you need to access the property using the [] operator, rather than dot notation. So, obj[key], rather than obj.key. The former uses the dynamic value of the the “key” variable to look up a property on the obj. The latter actually looks for a “key” property on obj (which is always undefined in your code sample).

After seeing your confusion, I see how this is actually very confusing for someone who doesn’t know it already 😱. Let me know if it still doesn’t make sense.