Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Stuck like chuck any suggestions (Javascript)

How would you get the number 123 out of this object using one line of JavaScript?.

var myCrazyObject = {

"name": "A ridiculous object", "some array": [7, 9, { purpose: "confusion", number: 123 }, 3.3], "random animal": "Banana Shark" };

2 Answers

Hey Double RR,

As crazy as that object is, it's actually very straightforward to pull that number out. You just delve into the object itself and use brackets and quoted references to names when they are named keys with spaces (if they don't have spaces you can use dot notation) and numbers for indices when it is an array. So, here's two versions of your one line =]

myCrazyObject["some array"][2]["number"];

OR:

myCrazyObject["some array"][2].number;

Good look for the assist Marcus appreciate it. I was close but no cigar Thanks again!!!!!!!!!!!!

No doubt, RR! Haha