[英]VS code debug - is replacing object values with ellipses. How to show object values in debug?
如何讓調試控制台顯示排序對象的實際值?
VS Code 調試控制台中的結果顯示如下,並且不可擴展:
[{…}, {…}, {…}, {…}, {…}, {…}]
No debugger available, can not send 'variables'
這是一個輸出我用 VS Code 編寫的排序對象的簡單程序。
const items = [
{ name: 'Edward', value: 21 },
{ name: 'Sharpe', value: 37 },
{ name: 'And', value: 45 },
{ name: 'The', value: -12 },
{ name: 'Magnetic', value: 13 },
{ name: 'Zeros', value: 37 }
];
// sort by value
items.sort(function (a, b) {
return a.value - b.value;
});
// console.log(items);
這是 launch.json 文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
重要提示:此解決方案僅在您使用 Node.js 時有效。
如果您使用的是 Node.js,則可以使用內置的util.inspect()
函數。
首先,您必須使用require()
導入它。
const util = require("util");
然后,您可以調用inspect
函數。 您需要將對象作為參數傳入。
const inspected = util.inspect(obj);
console.log(inspected);
然后,您可以輕松地看到對象而不會被壓縮! 有關詳細信息,請參閱util.inspect()
文檔。
如果您不使用 Node.js,則可以使用JSON.stringify()
。 您可以簡單地使用它,將對象作為參數傳遞。
const obj = [ { name: "Edward", value: 21 }, { name: "Sharpe", value: 37 }, { name: "And", value: 45 }, { name: "The", value: -12 }, { name: "Magnetic", value: 13 }, { name: "Zeros", value: 37 } ]; console.log(JSON.stringify(obj));
這應該允許您正確檢查它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.