i have the following object array
var parameter = "B001";
var my_array = [
{
"Shippment_out" : "2020-05-10",
"Batch" : "B001",
"Truck_No" : "ZB001"
},
{
"Shippment_out" : "2020-05-10",
"Batch" : "B002",
"Truck_No" : "ZB001"
},
{
"Shippment_out" : "2020-05-11",
"Batch" : "B001",
"Truck_No" : "ZB002"
},
{
"Shippment_out" : "2020-05-11",
"Batch" : "B002",
"Truck_No" : "ZB002"
},
]
i planning sort this by the parameter, if i pass batch no as B001 then the array should be sorted by B001 first then B002 together with earlier date first. in this case "2020-05-10".
likewise if i pass "B002" then "B002" then "B001". again earlier date first.
i tried my_array.sort(function (a, b) {}) but not able to implement the logic.