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
Brad Brown
Full Stack JavaScript Techdegree Student 1,804 PointsWhat is the difference between an array and an object?
Can someone explain to me what the difference is between an array and an object?
Am I correct in saying that a 2-dimensional array can store the same information an object can?
Why and when should you use one over the other?
2 Answers
Robert Bennett
11,927 PointsHi, I found my self in the same spot... Here is the conclusions - It is how you are using it... The example will demonstrate. All things are objects - because you can turn anything into an object and all objects have Properties and Methods... But the out comes can be different: look at the example below: it says it is a object but prints out an array.. LOL... Javascript
Here is a good link that treehouse doesn't teach on here to this extent. I think this should be the first thing to learn and understand. This took my programming skills up 3 notches... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
Robert Bennett
11,927 PointsI hope: I been at this for a year and I learn things every day... What I found out is slow down in the beginning and learn first. When I started to do that I went faster later on. Like what is () mean? Or what is => mean? or what does . mean. Here is the answer on the . Think that the . is a key into "Methods which are Nouns = Person.Place or Thing and Properties which are verbs that can act upon or be acted upon. Lets say a Car which is a noun which is a Method. But a car can have action - go fast which is a Property. These Properties and Methods can go on and on... But once you catch this you will understand what the arrays and objects and functions are!.
Brad Brown
Full Stack JavaScript Techdegree Student 1,804 PointsBrad Brown
Full Stack JavaScript Techdegree Student 1,804 PointsThat is awesome Robert, thank you. I have bookmarked that MDN resource. Something tells me I'll be reading through that a few more times over the weeks and months to come.