Dumping whole array: console.log and console.dir output "... NUM more items]"

Anthony picture Anthony · Jan 16, 2017 · Viewed 29.8k times · Source

I am trying to log a long array so I can copy it quickly in my terminal. However, if I try and log the array it looks like:

['item',
 'item',
  >>more items<<<
  ... 399 more items ]

How can I log the entire array so I can copy it really quickly?

Answer

Michael Hellein picture Michael Hellein · Jan 12, 2018

Setting maxArrayLength

There are a few methods all of which require setting maxArrayLength which otherwise defaults to 100.

  1. Provide the override as an option to console.dir

    console.dir(myArry, {'maxArrayLength': null});
    
  2. Set util.inspect.defaultOptions.maxArrayLength = null; which will impact all calls to console.log and util.format

  3. Call util.inspect yourself with options.

    const util = require('util')
    console.log(util.inspect(array, { maxArrayLength: null }))