0

I'm using VS Code as text editor for JavaScript, and Node.js for debugging my codes. When I debug the following code I get something called Object, I suppose it refers to something, but why doesn't it display what it refers to, and how can I do it? Is it related to my code?

function arrayToList(array) {
    let list = null;
    for (let i = array.length - 1; i >= 0; i--) {
      list = {value: array[i], rest: list};
    }
    return list;
}
let a = arrayToList([1,3]);
console.log(a);

This is the result (I also added a screen shot of it):

> Object {value: 1, rest: Object}

What is shown in Debug Console

Omer T
  • 35
  • 1
  • 10
  • 2
    Does this answer your question? [How can I get the full object in Node.js's console.log(), rather than '\[Object\]'?](https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object) – slim Jan 29 '20 at 15:11
  • 1
    JSON objects can be accessed by `.` e.g: `a.value` this will print 1 – Najam Us Saqib Jan 29 '20 at 15:12
  • May I ask what your are trying to accomplish with `rest` ? – ram Jan 29 '20 at 15:26

2 Answers2

3

Vs code will only show the top levels. It wont show an object inside of an object. But you can do something like this to still show the entire object:

console.log(JSON.stringify(a));

OR:

console.log(a.rest)
Kevin.a
  • 4,094
  • 8
  • 46
  • 82
0

Try

console.log(JSON.stringify(a)) Or

console.log(a.rest)