Вы можете использовать Array.prototype.sort () с функцией компаратора.Здесь я сначала проверил столбцы с наименьшим приоритетом, а затем один с наивысшим приоритетом.Он жестко запрограммирован, поэтому не применим к любой ситуации, но он работает.
Я намеренно добавил больше элементов в массив (некоторые с неправильными идентификаторами стран), чтобы упорядочить элементы с правильным приоритетом.
var x = [{
destination_country_id: null,
primary_cost: "9.50",
region_id: null,
destination_country_name: "Everywhere Else",
name: "xyz",
place: "abc"
},
{
destination_country_id: 105,
primary_cost: "8.00",
region_id: null,
destination_country_name: "United Kingdom",
name: "xyz1",
place: "abc1"
},
{
destination_country_id: 209,
primary_cost: "9.50",
region_id: null,
destination_country_name: "United States",
name: "xyz2",
place: "abc2"
},
{
destination_country_id: 124,
primary_cost: "5.00",
region_id: null,
destination_country_name: "Ireland",
name: "xyz3",
place: "abc3"
},
{
destination_country_id: 124,
primary_cost: "3.00",
region_id: null,
destination_country_name: "Ireland",
name: "xyz3",
place: "abc3"
},
{
destination_country_id: 123,
primary_cost: "5.00",
region_id: null,
destination_country_name: "Ireland",
name: "xyz3",
place: "abc3"
}
];
x.sort(function(a, b) {
var return_value = 0;
var destName_A = a.destination_country_name.toUpperCase();
var destName_B = b.destination_country_name.toUpperCase();
var destID_A = a.destination_country_id;
var destID_B = b.destination_country_id;
var cost_A = a.primary_cost;
var cost_B = b.primary_cost;
if (cost_A < cost_B) {
return_value = -1;
}
if (cost_A > cost_B) {
return_value = 1;
}
if (destID_A < destID_B) {
return_value = -1;
}
if (destID_A > destID_B) {
return_value = 1;
}
if (destName_A < destName_B) {
return_value = -1;
}
if (destName_A > destName_B) {
return_value = 1;
}
return return_value;
});
console.log(x);
Надеюсь, я вас правильно понял.