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 trialPaul Messmer
15,023 Pointsif the issue with the arrays is people looking at the code and not knowing what it means couldnt you just add comments?
This would save several lines of code.
1 Answer
Alexander Ditto
17,433 PointsThe major issue with arrays as a way to pass complex information that is nuanced is that it is the coder is prone to error when creating the array and when referencing the array later in the code. If the array is simple like
let arr =[Ashely, Dear, 17];
it can be easy to call it later as
let bio = ${arr[0]} ${arr[1]} is ${arr[2]} years old.
;
The issues is when the array is filled with more complicated data like grades. let arr =[Ashely, Dear, 17, A, A, D, C, B]; Now remembering and transferring which grade is which is a nightmare. Objects are created for just this reason, let obj= {firstName : Ashely, lastName : Dear, age : 17, math : A, science : A, pe : D, art : C, language : B}; Calling from the object is much easier because you simply call the object.property like obj.name or obj.age
let mathGrade = obj.math;
Objects make JavaScript a lot easier to code on the front and back end. Plus, other coders will like you more if you use objects rather than mysterious arrays. I hope this helps.