javascriptを使用する私はいくつかの変数があります。生成された数値から変数を選択する
var item1 = {
name : 'apple',
color : 'red',
type : 'fruit'
//etc
};
var item2 = {
name : 'rose',
color : 'red',
type : 'plant'
//etc
};
数字に基づいて上記の項目を選択したいと考えています。私はこれのようにすると思った。
var select;
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
select = Math.floor(Math.random() * 2) + 1;
しかし、私はこれらのアイテムに電話するのに問題があります。私はそれがちょうどitem[select].name
などと思った。しかし、明らかに起こっていない。助けて?