Is there a way to access a property nested deep within an object when creating a custom sorting function?
I am attempting to implement a sort function that can sort an array based on a specific criteria.
const data = [
{
a: {
b: {
c: 2
}
}
},
{
a: {
b: {
c: 1
}
}
}
sortBy(array, criteria){
array.sort((a,b) => {
if (a[criteria] > b[criteria]) return 1;
...
}
}
While I understand the current code does not function as intended, my goal is to be able to utilize sortyBy(data, "a.b.c")
.