【发布时间】:2021-07-19 03:38:33
【问题描述】:
写入/读取数组内对象的变量属性的正确方法是什么?
let exampleArray = [];
let exampleProperty = "string";
let exampleValue = 10;
let arrayRowIndex = 5;
exampleArray[arrayRow][exampleProperty] = exampleValue; // this does not work
console.log( exampleArray[arrayRowIndex][exampleProperty] );
如果对象位于数组数组中,这会是什么样子?例如:
exampleArray[3][10].exampleObjecProperty
将变量用于索引和属性本身会怎样?
【问题讨论】:
-
"// 这不起作用" - 为什么要这样做?
exampleArray为空... -
“如果对象位于数组数组中,这会是什么样子?” - 对象的存储位置不会改变您添加/更改其属性的方式.
标签: javascript arrays object multidimensional-array