Sort array of objects in specific order

前端 未结 5 837
清酒与你
清酒与你 2021-02-11 04:14

I have an array of objects returning from an API call which I need to sort into a specific format.

I\'m trying to organise the destination_country_id alphab

5条回答
  •  执念已碎
    2021-02-11 04:23

    If your provided array is called list, you can sort it as you want using the following call:

    list.sort(function (item1, item2) {
        if (item1.destination_country_name < item2.destination_country_name) {
            return -1;
        }
        return 1;
    });
    

提交回复
热议问题