So I have this array that contains objects:

var terms = [
 {
  'class-1': {name: 'English', completed: '12/02/19', letterGrade: 'A'}, 
  'class-2': {name: 'Math', completed: '12/02/19', letterGrade: 'A'},
  'class-3': {name: 'P.E.', completed: '12/02/19', letterGrade: 'A'},
  'class-4': {name: 'World History', completed: '12/02/19', letterGrade: 'A'}
 },
 {
  'class-1': {name: 'P.E.', completed: '12/02/19', letterGrade: 'A'},
  'class-2': {name: 'World History', completed: '12/02/19', letterGrade: 'A'},
 },
 {
  'class-1': {name: 'P.E.', completed: '12/02/19', letterGrade: 'A'},
  'class-2': {name: 'English', completed: '12/02/19', letterGrade: 'A'},
  'class-3': {name: 'Math', completed: '12/02/19', letterGrade: 'A'},
 },
 {
  'class-1': {name: 'English', completed: '12/02/19', letterGrade: 'A'},
  'class-2': {name: 'Algebra', completed: '12/02/19', letterGrade: 'A'},
  'class-3': {name: 'Psychology', completed: '12/02/19', letterGrade: 'A'},
 }
]

And I want to sort each of the nested objects alphabetically on the name of the class. But I want the whole array to be sorted.

Not sure how I should go about doing this. What's holding me up is the amount of nests in the data.

Given the following input:

let classes = {
  'class-1': {name: 'P.E.', completed: '12/02/19', letterGrade: 'A'},
  'class-2': {name: 'English', completed: '12/02/19', letterGrade: 'A'},
  'class-3': {name: 'Math', completed: '12/02/19', letterGrade: 'A'},
}

You can separate each key/value pair into entries, sort those entries however you wish, and then re-assign to an object, like this:

let allEntries = Object.entries(classes)
let sortedEntries = allEntries.sort((a,b) => a[1].name.localeCompare(b[1].name))
let obj = Object.fromEntries(sortedEntries)

Which will produce the following result:

{
  'class-2': {name: 'English', completed: '12/02/19', letterGrade: 'A'},
  'class-3': {name: 'Math', completed: '12/02/19', letterGrade: 'A'},
  'class-1': {name: 'P.E.', completed: '12/02/19', letterGrade: 'A'}
}

Although do note that insertion order is not deterministic for js object properties

Demo in Stack Snippets

<!-- begin snippet: js hide: true console: true babel: false --> <!-- language: lang-js -->
let classes = {
  'class-1': {name: 'P.E.', completed: '12/02/19', letterGrade: 'A'},
  'class-2': {name: 'English', completed: '12/02/19', letterGrade: 'A'},
  'class-3': {name: 'Math', completed: '12/02/19', letterGrade: 'A'},
}

let allEntries = Object.entries(classes)
let sortedEntries = allEntries.sort((a,b) => a[1].name.localeCompare(b[1].name))
let obj = Object.fromEntries(sortedEntries)

console.log(obj)
<!-- end snippet -->