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?
Using
console.table
Available in Node v10+, and all modern web-browsers, you can use
console.table()
instead, which will output a beautiful utf8 table where each row represents an element of the array.Just found that option
maxArrayLength
works well withconsole.dir
too:console.dir(array, {depth: null, colors: true, maxArrayLength: null});
Setting
maxArrayLength
There are a few methods all of which require setting
maxArrayLength
which otherwise defaults to 100.Provide the override as an option to
console.log
orconsole.dir
Set
util.inspect.defaultOptions.maxArrayLength = null;
which will impact all calls toconsole.log
andutil.format
Call
util.inspect
yourself with options.What's wrong with
myArray.forEach(item => console.log(item))
?Ugly but this will work:
Wish there was a way to do this in native node.