如何在JavaScript中的多维2D数组中的关联数组中设置/获取值

问题描述

我想在JavaScript的2D数组中的关联数组中设置/获取值。我使用了以下源代码:

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);

我创建了2D数组,并在其中填充了 properties (关联数组)。然后在 listOfProperties [2] [2] 中为 isBold 设置 true ,为 isBold设置 false listOfProperties [0] [0] 中。

但是为什么 listOfProperties [2] [2] 中的 isBold 包含 false 而不是 true

我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)