How to return data from a json file in a growing way, different from the root of the objects? [closed]

0

I want to return data from a json file, however I want them to be printed on the page from the bottom up, ie the most recent data, which by default of the root are 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 as I believe it is a matter of algorithmic logic and can be exemplified with an array of JavaScript / Jquery objects.

    
asked by anonymous 28.11.2018 / 17:18

1 answer

1

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

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

arr.reverse();

arr.forEach(item => console.log(item));
    
28.11.2018 / 18:16