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>

asked Jan 7, 2023 at 3:06

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].

answered Jan 7, 2023 at 3:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.