-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Bug in console.log ? #11651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
@mscdex Simplified code: const obj1 = { prop: [{ prop: [1] }] };
const obj2 = { prop: { prop: [1] } };
const obj3 = { prop: [1] };
console.log(JSON.stringify(obj1));
console.log(JSON.stringify(obj2));
console.log(JSON.stringify(obj3));
console.log(obj1);
console.log(obj2);
console.log(obj3);
Why |
It’s I agree, this is confusing and we could at least turn it into |
It seems the depth inspect option matters. const util = require('util');
const obj1 = { prop: [{ prop: [1] }] };
const obj2 = { prop: { prop: [1] } };
const obj3 = { prop: [1] };
console.log(JSON.stringify(obj1));
console.log(JSON.stringify(obj2));
console.log(JSON.stringify(obj3));
console.log(util.inspect(obj1, { depth: null }));
console.log(util.inspect(obj2, { depth: null }));
console.log(util.inspect(obj3, { depth: null }));
|
Oh, and the square brackets are also a bit confusing here: |
@mscdex Thanks for the quick response. |
Prefer `[Array]` over `[Object]` because the latter is confusing. Ref: nodejs#11651 PR-URL: nodejs#12046
I have this code. As you can see, the stringified version of the obejct, and the representation used by console.log are different. Is it a bug, or a limitation in the console.log?
Output:
The text was updated successfully, but these errors were encountered: