[英]How to set/get value in associative array in multidimensional (2D) array in JavaScript
I would like set/get value in associative array in 2D array in JavaScript.我想在 JavaScript 中的二维数组中的关联数组中设置/获取值。 I used a following source code:
我使用了以下源代码:
var properties = { "isBold": false, "isItalic": false, "isUnderline": false }; // Creation of 2D array, 6x6 var listOfProperties = new Array(6); for (var i = 0; i < listOfProperties.length; i++) { listOfProperties[i] = new Array(6); } // Population of listOfProperties with properties for (var row = 0; row < listOfProperties.length; row++) { for (var col = 0; col < listOfProperties.length; col++) { listOfProperties[row][col] = properties; } } var property = listOfProperties[2][2]; property.isBold = true; // I would like to populate property isBold console.log("property > " + property.isBold); var property = listOfProperties[0][0]; property.isBold = false; console.log("property > " + property.isBold); var property = listOfProperties[2][2]; console.log("property > " + property.isBold);
I created 2D array which I populated with properties (associative array).我创建了用属性(关联数组)填充的二维数组。 Then I set a true for isBold in listOfProperties[2][2] and false for isBold in listOfProperties[0][0] .
然后我在listOfProperties [2] [2]和假用于isBold在listOfProperties [0] [0]设置为真isBold。
But why isBold in listOfProperties[2][2] includes false instead true ?但是为什么listOfProperties [2][2]中的isBold包含false而不是true ?
What I do wrong?我做错了什么?
抱歉这个问题我没有注意到我忘记为 listOfProperties[2][2] 设置一个 true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.