I have the following array
[
  {
    "id": 1,
    "name": "Ruan Duarte",
    "idade": 11,
    "work": {
      "id": 2
    }
  },
  {
    "id": 2,
    "name": "Raul Dias",
    "idade": 13
  },
  {
    "id": 7,
    "name": "Caio",
    "idade": 60,
    "work": {
      "id": 4
    }
  },
  {
    "id": 3,
    "name": "Felipe Lima",
    "idade": 55
  },
  {
    "id": 4,
    "name": "Camila",
    "idade": 25,
    "work": {
      "id": 3
    }
  }
]
I have an array in this format, where the work.id field in some corners is null. I try to do the ordering as follows ...
array.sort((a, b) => {
  return (
    a.work.id - b.work.id
  )
})
However, I get an error for the non-existence of the id
 
     
     
     
    