Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
How can I change the name of the key in an object using "for ... in"

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);
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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']
about 4 years ago · Juan Pablo Isaza Report

0

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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!