I'm struggling to sort an array of objects by two different keys. I need to first sort the array by price, and if there are multiple items with the same price, they should then be sorted by time. Here's what my array looks like:
var myArr = [
{"value":5 , "price"=10, "time":3},
{"value":1.5 , "price"=2, "time":2},
{"value":3 , "price"=5, "time":4},
{"value":1 , "price"=2, "time":1}
]
After sorting, the array should look like this:
var myArr = [
{"value":1 , "price"=2, "time":1},
{"value":1.5 , "price"=2, "time":2},
{"value":3 , "price"=5, "time":4},
{"value":5 , "price"=10, "time":3}
]
I've tried various methods but haven't been able to solve it due to the complexity of sorting by two keys simultaneously.