我想在表格中显示字符属性,我该怎么做?它当前记录整个对象并且在我使用 console.table(tileGridArray.char) 时未定义
const tileGridArray = [];
for (let rowIndex = 0; rowIndex < 3; rowIndex++) { // Loop through each row
const row = [];
for (let colIndex = 0; colIndex < 3; colIndex++) { // Loop through each column in the current row
const tileObj = {
row: rowIndex,
col: colIndex,
type: null, // mine true of false
visibility: null,
char: 'why'
};
row.push(tileObj);
}
tileGridArray.push(row); }
console.table(tileGridArray)
要在表格中只显示
char
属性,可以创建一个新数组,只包含tileGridArray
中每个对象的char属性,然后将该数组传递给console.table()
。
const charArray = tileGridArray.map(row => row.map(tileObj => tileObj.char));
console.table(charArray);