访问嵌套的json对象的属性将返回undefined

时间:2016-05-07 01:10:23

标签: javascript json object nested

var voice1 = Voice() // replaces the AKSampler

seq = AKSequencer(filename: "seqDemo", engine: AudioKit.engine)
seq.loopOn()
//seq.avTracks[0].destinationAudioUnit = voice1.oscillator.avAudioNode
seq.note = voice1.oscillator.frequency // "note" doesn't actually exist in the API

方法1:

var validCoins = {
      "nickel": {
        "weight": 5.00,
        "diameter": 21.21,
        "thickness": 1.95,
        "value": 0.05
      },
      "dime": {
        "weight": 2.27,
        "diameter": 17.91,
        "thickness": 1.35,
        "value": 0.10
      },
      "quarter": {
        "weight": 5.67,
        "diameter": 24.26,
        "thickness": 1.75,
        "value": 0.25
      }
    };

方法2:

Object.keys(validCoins).forEach(function(coinType) {
      alert(coinType.weight);
}

这些似乎都不起作用,它返回undefined,我错过了什么? (我是否必须导入库或其他内容?)我打算使用普通的javascript。

1 个答案:

答案 0 :(得分:1)

some random, text

Fiddle