-1

Description

I have an ES6 map. 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)

The problem

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].

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'].

What I've tried

On searching for existing issues, I tried two things without success -

  • using .fill() on the array (I thought it evaluates the array, but it doesn't)
  • I tried using JSON.stringify, but sadly it does not support ES6 Maps yet.

I guess this has to do with JavaScript's style of lazy-loading values in the console.

I need to print the elements instead of [Array] in the console.

Nina Scholz
  • 376,160
  • 25
  • 347
  • 392

1 Answers1

1

No. it is not possible, because console is not configurable.

Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
  • Appreciate the answer, but I can of course access the array values! I believe the question needs an edit about what is being asked. –  Aug 26 '20 at 16:03