代码之家  ›  专栏  ›  技术社区  ›  xXx

如何在javascript中从Datastructure中按名称获取对象[duplicate]

  •  -3
  • xXx  · 技术社区  · 7 年前

    我有以下Javascript格式的Datastructur

      data: {…}
            0_0: {…}
                file: “xy.jpg”
                height: 256
                width: 256
                <prototype>: Object { … }
            0_256: {…}
                file: "xx.jpg"
                height: 256
                width: 256
            <prototype>: Object { … }
    

    如何从“0*256”中获取数据?

    2 回复  |  直到 7 年前
        1
  •  2
  •   Ankit Agarwal    7 年前

    你需要使用 data['0_256'] :

    var data = {
        '0_0': {
              file: "xy.jpg",
              height: 256,
              width: 256
         },
        '0_256': {
              file: "xx.jpg",
              height: 256,
              width: 256
        }
    };
    console.log(data['0_256']);
        2
  •  1
  •   Rupesh Agrawal    7 年前

    您可以尝试“data['0\u 256']”

    `console.log(data['0_256'])`
    

    var   data = { 
            "0_0" :{
                file: "xy.jpg",
                height: 256,
                width: 256
                },
            "0_256":{
                file: "xx.jpg",
                height: 256,
                width: 256
                }
              }
    console.log(data['0_256']);