Changing the name of keys in an object [SOLVED]

I have an array and an object like this:

var arr = ["dog", "cat", "bird", "bee"];
var obj = { "dog": true, "cat": true, "bird": true, "bee":  true };

within my interface I update the name of of the elements in arr, i.e. “cat” to “cow”;

var oldElem = "cat";
var newElem = "cow";

so the array looks like this:

var arr = ["dog", "cow", "bird", "bee"];

I also want to update my object and do this:

 if (oldElem !== newElem) {
	Object.defineProperty(obj, newElem,
	    Object.getOwnPropertyDescriptor(obj, oldElem));
	delete obj[oldElem];
	}

this almost works.

obj = {"dog": true, "bird": true, "bee": true, "cow": true}

as you can see, the “cow” is being added as a new key, with value “true”, but as the last element of “obj”.
It’s crucial that it has exact same position as “cat”.
How to achieve that?

You really can’t, the keys of an object don’t really have an order as you would want them to do
[From Exploring ES6]

All methods that iterate over property keys do so in the same order:

  1. First all Array indices, sorted numerically.
  2. Then all string keys (that are not indices), in the order in which they were created.
  3. Then all symbols, in the order in which they were created.

Thanks for the reply.

I actually figured it out. In a real nutshell:
I used this function

const renameKeys = (keysMap, obj) =>
  Object.keys(obj).reduce(
    (acc, key) => ({
      ...acc,
      ...{ [keysMap[key] || key]: obj[key] }
    }),
    {}
  );

created an object

var newKeys = { "dog": "dog", "cat": "cow", "bird": "bird", "bee":  "bee" };

and passed it to the function

renameKeys(newKeys, obj);

it returns the “cow” on the right position

I used this very helpful hint