让js去找显示出来的东西?

Let js look for the thing that was shown?

在 json 文件中我有这个

{
"Class Token - Scout": {
    "defindex": [5003],
    "prices": {
        "3": {
            "Tradable": {
                "Craftable": [{
                    "value": 244,
                    "currency": "keys",
                    "difference": 266,
                    "last_update": 1339261330
                }]
            }
        },
        "6": {
            "Tradable": {
                "Craftable": [{
                    "value": 0.16,
                    "currency": "metal",
                    "difference": 0.05,
                    "last_update": 1341200357
                }]
            }
        }
    }
}
}

我的密码是

//The price of an item
const price = require('./price.json')

//Things i have
var item = 'Class Token - Scout'


if(item == price){
    console.log(price.defindex)
    console.log(price.prices.6.Tradable.Craftable.value)
}

我希望它在 price.json 文件中搜索项目名称是否存在,如果是 return 项目的 defindex 和值

您错过了重要的一步:

//The price of an item
const price = require('./price.json')

//Things i have
var item = 'Class Token - Scout'


const itemPrice = price[item];

if (itemPrice){
    console.log(itemPrice.defindex)
    console.log(itemPrice.prices['6'].Tradable.Craftable.value)
}