This gives you more control and lets you add conditional logic if needed. The hasOwnProperty check stops undefined values from getting added when keys don’t exist. Performance is about the same as other solutions, but it’s easier to modify later.
Had this exact problem a few months ago building a form component that needed consistent field ordering. Cleanest fix I found was Object.fromEntries() with map(). Here’s what worked:
Super straightforward and handles missing keys gracefully by setting them to undefined. I like it better than reduce methods - more readable and easier to debug. Just make sure your key order array has all the properties you need, or you’ll lose data from the original object.