According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#description:
The traversal order, as of modern ECMAScript specification, is well-defined and consistent across implementations. Within each component of the prototype chain, all non-negative integer keys (those that can be array indices) will be traversed first in ascending order by value, then other string keys in ascending chronological order of property creation.
Or this easier to understand resource: https://javascript.info/object#ordered-like-an-object
So I believe you could do the following:
object1 = {
test: {},
test2: {},
users: {},
colors: {},
dates:{}
};
object2 = {
test2: {},
dates:{},
test: {},
colors: {},
users: {}
};
orderedObject2 = {};
for (let prop in object1){
orderedObject2[prop] = object2[prop];
}
object2 = orderedObject2;
// now all the matching properties of object2 are in same order as in object1