Node.js: Log over 100 Array elements


2018-04-12 · 1 min read

Using console.log on an array with over 100 elements results in the following output

// file.js
const arr = Array(500).fill('item');
console.log(arr)
node file.js

[ 'item',
  'item',
  'item',
  <...cut...>
  'item',
  'item',
  'item',
  ... 400 more items ]

Only first 100 are displayed with a message that there are more elements.

Use util.inspect with maxArrayLength set to null to display more than 100 items from an array:

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

By default, in Node.js maxArrayLength is set to 100.