[solved] How to loop JSON object array

#1

Hello all.

  1. My goal is: interact with JSON array
  2. My actions are:
    my input is this JSON
let obj = {"pinout":[{"id":18,"value":0},{"id":19,"value":1}]} ;
for(i in obj.pinout){
        print (i);
      }
  1. The result I see is:

> MJS callback error: [i] is not defined

  1. My expectation & question is:
print output: 0
print output: 1
#2

Try for (let i in obj.pinout)

1 Like
#3

Read the mJS definition, all variables must be defined before utilization.

1 Like
#4

@nliviu
Perfect! Well, I need to get familiar with the limitation. It is not exactly javascript.
Thank you again.

@scaprile
That is great! I would like to have more code samples. This is a great source of information.
For many times, I just realized that something is wrong when I put the init.js file into the device.