Skip to content
Advertisement

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:

JavaScript

This code is wrong because the result is

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

Advertisement

Answer

You have to do it in two steps

JavaScript

Alternatively, store 111 in a variable first

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement