Hello
I try to rename a key from an Object, but keeping the order of the keys (index).
If the new key is text (string), everything is OK.
But, if the new key is a number (although it is declared as a string), the new key moves to the first position in the index.
I tried various options, but I can't get the desired result.
[{"id":"92465edc.815478","type":"debug","z":"821f0ea6.3f40c","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":2000,"wires":[]},{"id":"60f2794a.5d981","type":"inject","z":"821f0ea6.3f40c","name":"Go","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":600,"y":2000,"wires":[["5f38886b.237468"]]},{"id":"5f38886b.237468","type":"function","z":"821f0ea6.3f40c","name":"RenameKeys","func":"let obj = { \n COL1: \"A\",\n COL2: \"B\",\n COL3: \"C\"\n};\n\nlet keys = Object.keys(obj)\nmsg.oldKeys = keys // debug only\n\n\nlet oldKey = \"COL2\";\n//let newKey = \"xxx\"; // OK [\"COL1\",\"xxx\",\"COL3\"]\nlet newKey = \"2\"; // NOT OK [\"2\",\"COL1\",\"COL3\"]\n\n\n\nlet newObj = {};\n\nkeys.forEach( e => {\n if (e == oldKey) newObj[newKey] = obj[e]\n else newObj[e] = obj[e]\n})\n\nmsg.newKeys = Object.keys(newObj) // debug obly\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":2000,"wires":[["92465edc.815478"]]}]