0

I'm using axios to fetch ordered array from server. The server return the array in ordered for example ( [A, B, C] ) but axios shuffle the array return in random order. Every time a new call is made, it returns array in complete random order for example [A, C, B], [B, A, C], [C, A, B] or [A, B, C] .

async (url, ...args) => {
   const response = await axios.get(url);

    return response.data;
}

I want to get the array in the same order as the server sent back.

Emile Bergeron
  • 14,368
  • 4
  • 66
  • 111
user4900074
  • 731
  • 1
  • 9
  • 24
  • I'm pretty sure that's not axios that's shuffling the array and most likely your backend at serializing time. You could make sure that the response is ordered correctly by checking the raw data in the network tab of the dev tools. – Emile Bergeron Sep 10 '19 at 15:47
  • If your backend is Php, it's possibly related to: [json_encode not preserving order](https://stackoverflow.com/q/20912492/1218980) – Emile Bergeron Sep 10 '19 at 15:49
  • thank you for your reply. I get the correct order in insomnia, and also when I paste the url directly in the browser. We have java in backend. – user4900074 Sep 10 '19 at 15:57
  • Please, include the JSON of the response in the question itself. – Emile Bergeron Sep 10 '19 at 15:58
  • 1
    Ugh! you're totally, right. I was checking the wrong end-point. The one that I was making a call to returns random list. It's definitely backend problem. I wasted half a day trying to figure that out. :( – user4900074 Sep 10 '19 at 17:17

1 Answers1

-1

Convert the array into list of objects with numbered keys.

ex:

{
0:value1,
1:value2,
2:value3
}
Ajay Ghosh
  • 360
  • 1
  • 11