var obj = {a:1,b:2}; for (var in obj) { alert (x); Alert (Obj[x]) }
1. Pop up A, 1, B, 2 in turn. ( Note that the value in the loop is obj[x], while the general operation of the JSON array is obg.a. )
2.OBJ.A is 1 obj.b is 2;
Instance:
Today, when I wrote the pop-up window plugin, I encountered a problem,
The BTS here is the parameter that pops up within two buttons, the key denotes "The word inside the button", and the value denotes "the function that the button executes."
Both of these are user-defined, so they are variables;
So how do we get the parameters that the user passed in and convert to HTML (that is, the word inside the button) and the function to execute.
1. Use for in to get the key, value of the user's passed in parameter (OPTION.BTS):
1 varoption =$.extend (duf,options)2 varBtsarray =NewArray ();3 varBtsfnarr =NewArray ();4 for(varXinchOption.bts)5 {6 Btsarray.push (x);7 Btsfnarr.push (option.bts[x]);8 }; 9 varOksarray = btsarray[0];Ten varNosarray = btsarray[1];
Also, the key values are stored in an array to facilitate the operation of the value.
2. The next operation is to put the variable array btsarray in the corresponding place when rendering the HTML.
3. Finally put the variable array btsfnarr into the corresponding button operation function is OK.
OBJ{A:1,B:2} Health Value operation