[英]Evaluate an array inside an ES6 map to actually print elements on console
I have an ES6 map.我有一个 ES6 地图。 It has a string key, whose value is an array of maps.
它有一个字符串键,其值是一个映射数组。
The following minimal reproducible code best describes it -以下最小的可重现代码最好地描述了它 -
var rootMap = new Map()
rootMap.set('details', [])
var subMap = new Map()
subMap.set('items', ['foo', 'bar'])
// Append subMap to the array in rootMap
rootMap.get('details').push(subMap)
console.log(rootMap)
Upon running the snippet, I see this in the terminal -运行代码段后,我在终端中看到了这一点 -
Map(1) { 'details' => [ Map(1) { 'items' => [Array] } ] }
I need to get the array values foo
and bar
show up on the console, instead of [Array] .我需要在控制台上显示数组值
foo
和bar
,而不是[Array] 。
EDIT: I can of course log the values by accessing indexes, but this question is really asking to know if it is possible to (literally) replace [Array]
with the value ['foo', 'bar']
.编辑:我当然可以通过访问索引来记录值,但是这个问题实际上是想知道是否可以(字面意思)将
[Array]
替换为值['foo', 'bar']
。
On searching for existing issues, I tried two things without success -在搜索现有问题时,我尝试了两件事但没有成功-
.fill()
on the array (I thought it evaluates the array, but it doesn't).fill()
(我认为它会评估数组,但事实并非如此)JSON.stringify
, but sadly it does not support ES6 Maps yet.JSON.stringify
,但遗憾的是它还不支持 ES6 Maps。 I guess this has to do with JavaScript's style of lazy-loading values in the console.我想这与 JavaScript 在控制台中延迟加载值的风格有关。
I need to print the elements instead of [Array]
in the console.我需要在控制台中打印元素而不是
[Array]
。
不,这是不可能的,因为console
是不可配置的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.