Sort object by value in javascript [duplicate]

My ajax is returning the response as below.


    Array(7)
0
: 
{id: 1, name: 'A-DragonFruit'}
1
: 
{id: 2, name: 'A-Grapes}
2
: 
{id: 3, name: 'A-Mango'}
3
: 
{id: 4, name: 'A-Banana'}
4
: 
{id: 5, name: 'B-Kiwi'}
5
: 
{id: 6, name: 'A-Papaya'}
6
: 
{id: 7, name: 'B-SomeOtherFruit'}
7
length
: 
7
[[Prototype]]
: 
Array(0)
[[Prototype]]
: 
Object

Then I am just getting an Id and name from here using map function like below.

let data = {};
response.data.map((i) => { data[i.id] = i.name; });

But this sorts the object by id automatically in ascending order and gives the result sorted by id.

How can I create this object with id and name in ascending order of values (in my case fruits) and not by their id’s. I need Id and name both in my data object.

Thanks in advance.