Loading json data in to an array

this is json
[{“id”:2,“userid”:30, “start_time”:“2019-09-01 14:13:35”},{“id”:3,“userid”:340, “start_time”:“2019-08-01 14:13:35”}]

public items: any;

loadPeople(){
this.remoteService.load()
.then(data => {
console.log(data);
this.people = data;
});

ı can pull json and display in the page very well. But ı want store this.people in to items array depend on start_time which is the earliest. Hopefully ı was able to explain problem

If you want to order your array by start_time, you can use the array sort method.

this.people.sort((x,y) => new Date(x.start_time) - new Date(y.start_time))

thank you so much thats work

1 Like