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

144
Views
I am not understanding why this is displaying out of order

I have an object. I pull the keys and values and place in separate arrays. I then put them back together but in reverse. It keeps placing the second item first.

const obj = { keyname: 'Greg', keyage: 40, keyjob: 'cook'};
console.log(_.invert(obj));

    invert (object) {
      let keyArr = Object.keys(object);
      let valueArr = Object.values(object);
      const result = {};
      valueArr.forEach((value, i) => result[value] = keyArr[i]);
      return result;
    }

I am expecting to get a result of

{ Greg: 'keyname', 40: 'keyage', cook: 'keyjob' }

but instead i get

{ '40': 'keyage', Greg: 'keyname', cook: 'keyjob' }

why?

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