null
const example1 = {
subex1: {
...something...
},
subex2: {
...something...
}
};
null
这是密码。 由于某种原因,我不能使用example1[math.flood(math.random()*example1.length)]
代码。 我如何从子常量中获得一个随机项(如果它们不是子常量,实际上idk它们的名称)。
你可以做这样的事。
null
const example1 = {
subex1: {
"hello": "hello"
},
subex2: {
"Hello1": "hello1"
}
};
console.log(Object.keys(example1)[Math.floor(Math.random()*Object.keys(example1).length)]);