How to return data from a json file in an increasing way, different from the root of the objects?

Asked

Viewed 93 times

0

i want to return data from a json file, but I want it to be printed on the bottom page up, that is, the most recent data, which by default is written from top to bottom in json, always appear at the top of the page, as a news feed. I will not put the code here because I think it is more a matter of algorithm logic and can be exemplified with an array or Javascript/Jquery objects.

  • Luan, the logic is just to iterate on your JSON backwards. If you need more details it would be interesting to add more information, such as the JSON structure you receive, for example.

1 answer

1


If what you want is to sort an array (in your case json) in reverse order, just use the method re-verse of the object Array.

const arr = [
  {name: 'jose', idade: 32},
  {name: 'ana', idade: 36},
  {name: 'fran', idade: 34}
];

arr.reverse();

arr.forEach(item => console.log(item));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.