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

135
Views
How to assign an object property value as a key in the same object?

Is there a way to assign a value of an object property as a key in the same object?

Like this:

var o = {}
o = {
    a: 111,
    b: 222,
    [o.a]: 'Bingo'
};

This code is wrong because the result is

{a: 111, b: 222, undefined: 'Bingo'}

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

0

You have to do it in two steps

var o = {
    a: 111,
    b: 222
};
o[o.a] = 'Bingo';

console.log (o);

Alternatively, store 111 in a variable first

var x = 111;
var o = {
    a: x,
    b: 222,
    [x]: 'Bingo'
};

console.log (o);

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!