0

How can I get the debug console to display the actual values of the sorted object?

The result in the VS Code debug console display as below and are non expandable:

[{…}, {…}, {…}, {…}, {…}, {…}]
No debugger available, can not send 'variables'

Here is a simple program outputting a sorted object that I have written in 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);

Here is the launch.json file:

{
    // 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": []
}
David S
  • 3
  • 1
  • Use `JSON.stringify` or `utils.inspect` if it's NodeJS (the latter provides options for inspection depth). – Dave Newton Apr 09 '22 at 19:00
  • 1
    They both work well (utils.inspect looks a lot neater!) thanks. – David S Apr 09 '22 at 19:18
  • Yup, I stumbled across it accidentally only recently and it's been super-helpful working w/ deeply-nested JSON :) – Dave Newton Apr 09 '22 at 19:56
  • Does this answer your question? [VSCODE: No debug adapter, can not send 'variables'"](https://stackoverflow.com/questions/61817528/vscode-no-debug-adapter-can-not-send-variables) – starball Feb 02 '23 at 18:56

2 Answers2

1

Important: This solution only works if you are using Node.js.

If you are using Node.js, you can use the built-in util.inspect() function.

First, you have to import it using require().

const util = require("util");

Then, you can call the inspect function. You need to pass in your object as a parameter.

const inspected = util.inspect(obj);
console.log(inspected);

Then, you can easily see the object without it being condensed! For more information, see the util.inspect() documentation.


If you are not using Node.js, you can use JSON.stringify(). You can simply use it as so, passing the object as a parameter.

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));

This should allow you to inspect it properly.

Arnav Thorat
  • 3,078
  • 3
  • 8
  • 33
0

Stringify worked but the output for mine is ugly AF! vscode really sucks in this regard! enter image description here

enter image description here

Scott Davis
  • 147
  • 1
  • 4
  • 10