私は 2 つの異なる方法でオブジェクトを作成し、それらに到達して操作しようとします。オブジェクトコンストラクターで作成したオブジェクトは機能しますが、リテラル表記でやろうとしているのと同じことが機能しません。理解できない。
これは、私よりも自分自身をよりよく説明するコードです:
var numberOne = new Object();
rand = Math.random();
numberOne[rand] = "random number";
console.log(numberOne); //return 0.6761925128922479: "random number"
var numberTwo = {}; //code doesnt work.
numberTwo.rando = Math.random();
numberTwo[rando] = "another random number";
console.log(numberTwo); //error