I'm looping over an object thats a list of terms for a student. The structure for my data looks like this:
terms: {
term-termId1: {
classData: { //some class data here that im not going to list },
class2 : { //some class data here that im not going to list },
class3 : { //some class data here that im not going to list },
termName: 'Spring 2018',
gradeLevel: 9,
},
term-termId2: {
classData: { //some class data here that im not going to list },
termName: 'Summer 2018',
gradeLevel: 9,
},
term-termId3: {
classData: { //some class data here that im not going to list },
class2 : { //some class data here that im not going to list },
termName: 'Summer 2020',
gradeLevel: 12,
},
term-termId4: {
classData: { //some class data here that im not going to list },
termName: 'Summer 2019',
gradeLevel: 11,
},
term-termId5: {
classData: { //some class data here that im not going to list },
termName: 'Summer 2019',
gradeLevel: 10,
},
term-termId6: {
classData: { //some class data here that im not going to list },
termName: 'Winter 2018',
gradeLevel: 9,
},
}
Thats all the data I'll give, the entries are scattered.
I'm trying to get the lowest gradeLevel entries first so I can pass them to a function that creates table components. So for example, I want all the gradeLevel: 9 s first, then 10s, then 11s then 12s.
I just want to know a good way to do this. I can think of a few ways, like writing some if statements in the loop, but im sure it can be done a better way.
Currently I'm starting out like this:
for (single in terms) {
for (term in terms[single]) {
const classes = terms[single]
console.log(classes[term])
}
}
I know that loop dosn't match the data I gave, thats just how i'm getting the data on my computer. I just gave an example.
Anyway, it would be great if I could get some help figuring out the best way to get the lowest gradeLevel entries first.