1

Glad to meet you all and to be here, currently I have a doubt that I am not understanding what is happening. Basicly I am mocking an api endpoint this way:

  mockFetchStatus(): Observable<IStatus> {
    const response = {
      bad: 4,
      normal: 5,
      good: 7,
      awesome: 12,
      notExpected: 22,
    };

    console.log('response: ', response);

    const obs: Observable<IStatus> = new Observable((subscriber) => {
      setTimeout(() => {
        subscriber.next({ ...response });
        subscriber.complete();
      }, 1000);
    });

    return obs;
  }

When I log my response data there, it is out of order, it started like in the numbers order 4 to 22. I tried the same example on codepen and the order is keeped. What is wrong with this code, any help?

  • Does this answer your question? [Does JavaScript guarantee object property order?](https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order) – SE_net4 the downvoter Apr 14 '21 at 11:22
  • Not really, that mentioned that if I have non integer keys, that is my case, then it should keep the order. I wanted to know if angular does some magic here since this doesn't make much sense. In codepen I just get my object back with the same order I created it – Filipe Costa Apr 14 '21 at 11:25

0 Answers0