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 Introduction to Programming Objects and Arrays Objects

console.log output of an Object inside of an Array inside of an Object

Hey guys! I'm getting a funny console.log output and I'd like to understand what it means.

Here is my code:

var user = {
    sample_array: [sampleObject = {
        item_one: "Test",
        item_two: "Test two",
        item_three: "Test three",
    }, "Sample Array"],
}

console.log(user.sample_array);

And here is a link to an image showing my console.log output: http://imgur.com/0m9y3ML

What does all of that mean, and why is it being shown in the first place?

1 Answer

Treasure Porth
STAFF
Treasure Porth
Treehouse Teacher

That's a list of built-in methods that every JavaScript object inherits from Object.prototype. So they are essentially built-in functions that are available to any JavaScript object automatically. You can find an explanation of what these methods do here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype

Thanks!