I want to use the for in function to change the keys. I know I could do it with map but can it be done with for in?
const meinObject = {
name: "Dominic",
plz: 9548,
};
for (let key in meinObject) {
key + "1" + meinObject[key]
console.log(key);
}
Ok, so what you can do is assign the value of your key to a new key, then delete the old key. This does not use a for in loop, it is something simpler.
obj['newKey'] = obj['oldKey'];
delete obj['oldKey'];
or in your case
meinObject['key'] = meinObject['newKey']
delete meinObject['key']
const meinObject = { name: "Dominic", plz: 9548, }; for (let key in meinObject) { key + "1" + meinObject[key] // this does not make sense var value = meinObject[key]; // get dominic, then plz etc. console.log('original', key, value); meinObject[key] = 'overwrite!!!'; var value = meinObject[key]; // get dominic, then plz etc. console.log('altered', key, value); } console.log('object after modification', meinObject);