Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

console.dir

Shows an object as a tree of properties.

Available since: Web API

Syntax

console.dir(object, options)

Parameters

ParameterTypeDescription
objectanyThe object to show.
optionsobjectOptional. In Node.js — for example depth: null to expand every level.

Return value

undefinedReturns nothing.

Examples

A deeply nested object in Node.js:

const config = { db: { primary: { host: 'localhost', port: 5432 } } };
 
console.dir(config, { depth: null });

Output:

{ db: { primary: { host: 'localhost', port: 5432 } } }

Notes

In the browser console.dir() shows a DOM element's properties while console.log() shows its HTML. In Node.js without depth: null objects nested deeper than two levels show as [Object].

See also

  • console.log — Prints values to the console.
  • console.table — Shows an array of objects as a table in the browser console.

In the tutorial

  • Debugging — How to find bugs in JavaScript: reading the error message, console.log and its variants, checking types, developer tools and debugger.

Thanks for reading!

Donate to the site — we work hard for you.