var privArr = []; privArr['staProjQueryGrid'] = [{ btn_id : 'but_add', roles : ['2001','2005'] }] console.log(privArr,privArr.staProjQueryGrid[0].btn_id)The first line is to define an array priArr, and the second line is to add a property staProjQueryGird to this array, and the value of this property is an array. The print result is but_add
var unPrivArr = [];//Create an empty array and assign it to unPrivArr['1000']=[];//Insert an empty array into the empty array unPrivArr, which is equivalent to unPrivArr[1000]=[]unPrivArr['1000']['aaa']={'but_check1':1,'but_check2':1};//Add an attribute named aaa to the empty array inserted above (because everything in js is an object, so the array is also an object, you can add properties and methods), and the property value is a new object (i.e. {'but_check1':1,'but_check2':1}).This is very different from the above. First of all, if there are numbers in the second line [], it means that the 1001st element of the array unPriArr is also an empty array (temporarily called x), and the first 1000 elements are undifined.
If it is a variable, it is an element of the array unPriArr
The third line is to add an attribute aaa to x, and the attribute value is an associative array {'but_check1':1,'but_check2':1}
You can use x['but_check1'] to get the corresponding value
I want to add attributes to the object associative arrays?
var unPrivArr = [];//Create an empty array and assign it to unPrivArr['1000']=[];//Insert an empty array into the empty array unPrivArr, which is equivalent to unPrivArr[1000]=[]unPrivArr['1000']['aaa']={'but_check1':1,'but_check2':1};console.log(unPrivArr[1000].aaa['but_check1'])This can output the result 1 correctly, or use unPrivArr[1000].aaa.but_check1 to output the result, but if you add quotation marks, it is wrong
If the third line is removed from the quotes in {}, the fourth number will report an error. At this time, you can only use unPrivArr[1000].aaa.but_check1
The detailed explanation of the associative arrays and ordinary arrays in the above article is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.