-4

have array [{id: 5}, {id: 1}, {id: 2}, {id: 0}] i wanna create sorted another array [{id: 0}, {id: 1}, {id: 2}, {id: 5}]. How i can do this with function filter?

Artur
  • 1
  • 1

1 Answers1

0

Use the sort method of the array to sort the values

array.sort(function(a, b) {
return a.id- b.id;
});
Joey Pinto
  • 1,735
  • 1
  • 18
  • 34