[英]How do I access nested objects properties in console.table()?
Lets say I have the following array of objects:假设我有以下对象数组:
var data = [
{ id: 123, author: { id: 123 } },
{ id: 123, author: { id: 123 } }
];
How can I populate a column in console.table with the id property of the author object?如何使用作者 object 的 id 属性填充 console.table 中的列?
This does not seem to work: console.table(data, ['id', 'author.id']);
这似乎不起作用:
console.table(data, ['id', 'author.id']);
I'm not sure you can do it with nested properties.我不确定您是否可以使用嵌套属性来做到这一点。
You could use map
to pull the data out into a better format and then console.table
it:您可以使用
map
将数据提取为更好的格式,然后使用console.table
它:
var out = data.map(function (el) {
return {
id: el.id,
authorId: el.author.id
};
});
console.table(out);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.