JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Mixing and Matching Arrays and Objects

Paul Messmer
Paul Messmer
9,283 Points

if 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
Alexander Ditto
14,328 Points

The 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 like 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.