Skip to main content
deleted 118 characters in body
Source Link
Sulthan
  • 564
  • 2
  • 13

You are doing it wrong. Object properties are unsorted by definition. See https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order

Your solution can break easily and I would be surprised if it worked it all browsersin the most difficult way possible.

What you actually want to do is to define the order of properties, e.g:

const propertyOrder = ['name', 'phone', 'email'];

or

const propertyOrder = Object.keys(object[0]).sort(...);

and render the properties bypass that order to your components with the object instead of using a random ordering of Object.keys.

You are doing it wrong. Object properties are unsorted by definition. See https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order

Your solution can break easily and I would be surprised if it worked it all browsers.

What you actually want to do is to define the order of properties, e.g:

const propertyOrder = ['name', 'phone', 'email'];

and render the properties by that order instead of using a random ordering of Object.keys.

You are doing it in the most difficult way possible.

What you actually want to do is to define the order of properties, e.g:

const propertyOrder = ['name', 'phone', 'email'];

or

const propertyOrder = Object.keys(object[0]).sort(...);

and pass that order to your components with the object instead of using a random ordering of Object.keys.

Source Link
Sulthan
  • 564
  • 2
  • 13

You are doing it wrong. Object properties are unsorted by definition. See https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order

Your solution can break easily and I would be surprised if it worked it all browsers.

What you actually want to do is to define the order of properties, e.g:

const propertyOrder = ['name', 'phone', 'email'];

and render the properties by that order instead of using a random ordering of Object.keys.