How can the data returned by the backend be sorted according to id?

`[

{name:a,id:1},
{name:c,id:5},
{name:b,id:2},
{name:y,id:4},
{name:s,id:6},
{name:p,id:3},

] `

how to sort from small to big according to id? It"s confusing whether
should use filter or map.

Aug.24,2021

var ary = [

{name:1,id:1},
{name:2,id:5},
{name:3,id:2},
{name:4,id:4},
{name:5,id:6},
{name:6,id:3},
]

console.log(ary.sort(function(x,y) {return x.id - y.id})
Menu