I have a list of teachers, each with a user
property that includes an image
. This image
property can either be a string
or null
. How can I sort the list based on the user.image
property?
Below is an example of the data structure.
const teachers = [
{
id: 1,
user: {
id: 10,
image: "image.jgp"
}
},
{
id: 3,
user: {
id: 30,
image: null
}
},
{
id: 2,
user: {
id: 20,
image: "image.jgp"
}
},
{
id: 4,
user: {
id: 40,
image: null
}
},
]