0

I have an object that has properties, but when I try to access them, it always returns undefined.

Using Chrome, I attached the object to window and in the console, if I do, window.country

It returns this object:

[ Object
currency_code: null
iso: "USA"
iso3: "USA"
name: "USA"
states: Array[51]
__proto__: Object
]

However, when I try to access a property, such as window.country.iso it's undefined. Any ideas why this would be?

Thank you!

5
  • 3
    please show the actual code that highlights the actual setting/getting of your object. Commented Jun 15, 2012 at 17:52
  • You execute window.country.iso in the console? Commented Jun 15, 2012 at 17:54
  • 3
    Is window.country an array? Do you need to do window.country[0].iso? Commented Jun 15, 2012 at 17:55
  • @Rocket yes, that was it, thank you! Weird chrome doesn't display that. Commented Jun 15, 2012 at 18:05
  • 2
    @dave It does display it. See the [ and the ]? That's it. Commented Jun 15, 2012 at 18:12

1 Answer 1

4

Your window.country object is actually an array.

Chrome's console is showing you that. As you can see your object is wrapped in [], that means it's in an array.

Try to access it like: window.country[0].iso.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.