Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does [Circular *1] mean (VS Code)

Console.log of an object with a circular reference in vscode displays includes following snippet: "[Symbol(network)]: [Circular *1]". I get why its circular, and I imagine the exact format is specific to VS Code but either way I would like to know more info - like what "*1" means.

Really surprised nothing comes up when I google '[Circular *1]'. What's the deal?

like image 575
PurpleMongrel Avatar asked Oct 20 '25 10:10

PurpleMongrel


1 Answers

It is a number indicating which object it is referencing:

const { inspect } = require('util');

const obj = {};
obj.a = [obj];
obj.b = {};
obj.b.inner = obj.b;
obj.b.obj = obj;

console.log(inspect(obj));
// <ref *1> {
//   a: [ [Circular *1] ],
//   b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }
// }

Check out how each object have a <ref *n> which reflect on [Circular *n].

like image 141
Gabriel Lima Avatar answered Oct 21 '25 23:10

Gabriel Lima