probably a really easy question for the intermediate and experienced programmer, but to me it is quite troubling:
I saw this code on a question here: (I am not sure if i am allowed to give the link but i the headline is:
Sort a numeric array inside of an object of arrays while keeping the order of the other arrays in the same order as the sorted numeric array)
const facilities = ["MD01", "PA01", "OH01", "NC01", "GA01", "SC01", "SC02", "TN01", "AL01", "FL02", "TX01", "IN01", "SC03", "FL01"];
const distances = [133, 32, 538, 422, 795, 666, 664, 822, 1118, 867, 1504, 657, 635, 1210];
const times = ["2 hours 12 mins", "47 mins", "8 hours 20 mins", "6 hours 32 mins", "12 hours 0 mins", "10 hours 2 mins",
"9 hours 56 mins", "12 hours 21 mins", "16 hours 33 mins", "12 hours 43 mins", "22 hours 16 mins", "10 hours 16 mins",
"9 hours 39 mins", "17 hours 35 mins"
];
const combined = facilities.map((facility,i) =>({facility, distance: distances[i], time: times[i]}))
.sort((a,b) => a.distance-b.distance)
console.log(combined)
while the code did the indeed give me an array of objects, i am now confused about how to access them. I have read somewhere that i can only access them within the callback function. On the other hand, i can console.log(combined).
I thought something along the lines would work, but nothing did:
console.log(combined.distances);
console.log(combined[0].distances);
console.log(combined[0].distances[0]);
console.log(combined[0].distance[0]);
And so on. I would have asked in comment on the thread, but since my score is too low and i am not confident in answering questions, i can only open a new one.