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

287
Views
JavaScript, get one object key name knowing the second

Let's say I have an object that has two key-values:

let object = {name: "abc", id: 12}

But let's say, I don't know one of the key-names, so:

let object = {<unknown_to_me>: "abc", id: 12}

How can I get the first key name if I know the other one? Their positions

THe first one is reachable via:

object.id

Can I get the other one by positions, the ! operator,...?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could do so:

let object = {name: "abc", id: 12};
let knownKeyName = "id";

let objectKeys = Object.keys(object);
let unknownKeyName = objectKeys[objectKeys.length - 1 - objectKeys.indexOf(knownKeyName)];

console.log(unknownKeyName)

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!