【问题标题】:Let js look for the thing that was shown?让js寻找显示的东西?
【发布时间】:2017-06-24 02:23:49
【问题描述】:

在 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 文件中搜索项目名称是否存在,如果它返回项目的定义索引和值

【问题讨论】:

  • item 是一个字符串,price 是一个对象,它们永远不会是==
  • 那我该怎么办,我是 js 新手,想不通

标签: javascript json node.js steam


【解决方案1】:

你错过了一个重要的步骤:

//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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多