Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite0
Why the first 'foo' is showing undefined as output? Would u pls help me to solve out the beneath problem?
var i = 0; var a = { ['foo' + i++]: i, ['foo' + ++i]: i, ['foo' + ++i]: i }; console.log(a.foo1); // 1 console.log(a.foo2); // 2 console.log(a.foo3); // 3
1 Réponse
+ 3
Put this line after definition for <a>
console.log( JSON.stringify( a ) )
You'll see that <a> doesn't have any member named 'foo1'.
(Edit)
In case you're wondering, why it has 'foo0', 'foo2' and 'foo3' members, but not 'foo1' - then know that the difference was due to the use of post and pre increment operator, which modifies value of <i> in different manner.