Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have type error. My variable creating this error while running with node.js. My variable is below. How can I describe my variable correctly ?

let allDevices = {
        1: {
            time: []
        },
        2: {
            time: []
        },
        3: {
            time: []
        }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
207 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm guessing you're trying allDevices.1.time to get the above error message. With numeric object keys, you'd need to reference the numbered object keys using [] instead of . notation:

let allDevices = {
  1: {
    time: []
  },
  2: {
    time: []
  },
  3: {
    time: []
  }
}

console.log(allDevices[1].time) // or allDevices['1'].time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...