Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/deno/cli/js/lib.deno.ns.d.ts>Deno.inspect

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.inspect
import { Deno } from "https://deno.land/x/deno@v1.0.0/cli/js/lib.deno.ns.d.ts";
const { inspect } = Deno;

Converts the input into a string that has the same format as printed by console.log().

 const obj = {};
 obj.propA = 10;
 obj.propB = "hello"
 const objAsString = Deno.inspect(obj); // { propA: 10, propB: "hello" }
 console.log(obj);  // prints same value as objAsString, e.g. { propA: 10, propB: "hello" }

You can also register custom inspect functions, via the customInspect Deno symbol on objects, to control and customize the output.

 class A {
   x = 10;
   y = "hello";
   [Deno.customInspect](): string {
     return "x=" + this.x + ", y=" + this.y;
   }
 }

 const inStringFormat = Deno.inspect(new A()); // "x=10, y=hello"
 console.log(inStringFormat);  // prints "x=10, y=hello"

Finally, a number of output options are also available.

 const out = Deno.inspect(obj, {showHidden: true, depth: 4, colors: true, indentLevel: 2});

Parameters

value: unknown
optional
options: InspectOptions

Returns

string