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
The difference between arrays sets and objects?
This question emphasizes on sets, could you explain the differences between these 3? Why would I use one instead of the other?
Thank you very much, Stavros
Regular arrays are 'Indexed Arrays' where as you already know you access individual properties by their index.
So the major difference between the two is that a regular array is indexed, where an object contains associations.
Tom Geraghty24,174 Points
To add on to what others have stated, this is just the language developing to more intuitively handle complex interactions. As software development deals with harder problems, people who write software end up finding patterns in the logic of their solutions. These patterns become recognized and used widely by other developers to make their software creation easier.
As these patterns get reused over and over, the people who decide what goes into a language sometimes incorporate those patterns and they become part of the core of the language's capabilities.
All computer programs do, essentially, is flip switches on and off (1 and 0). But we don't write programs by writing out huge series of 1s and 0s (at least, most people don't). These higher level abstractions like Boolean, Number, Array, Associative Array, Set, and so on are the evolution of the programming languages dealing with more and more complex problems.
It is certainly easier to write `var x = 5' than to write out the huge string of binary digits that the computer's transistors ultimately encode. It is also easier to use these higher level abstractions of data types (Number, Array, etc) to write solutions to more complex problems.
Long story short: Sets are used to store data types that should NOT be duplicated. There are a lot of math operations that rely on sets and knowing about those can help you design systems that use large amounts of data reliably.
The Set object lets you store unique values of any type, whether primitive values or object references.
Aaron Elliott11,738 Points