0

I have json data, now I'm trying to access it inside loop. But I got undefined.

Is there any way how to access it from loop?

var list = {
  macAddress: 'C0:49:EF:D3:79:20',
  category: 'esd',
  dr1: 1,
  dr2: 1,
  dr3: 0,
  dr4: 0
}

console.log(list);

for(var i=1; i<=2; i++) {
  var pinName = "dr" + i;
  
  console.log(list.pinName);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

1 Answer 1

2

List has no property pinName. You need the value of pinName to be evaluated as the key by calling list[pinName].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.