Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Seeing All of Your Nested Data

Seeing All of Your Nested Data

The website volunteer wants each rejected row kept whole. So Joan gathers one result, the month, the total and the rejected list, and checkRows() now gives each entry its line, its row (date, donor and amount) and the reason. In Python, the end of main() builds that dictionary and prints it on one long line, down to each row.

The port builds the same object, its keys without quotes, and total and rejected in shorthand, each a key named after its variable (total for total: total). Then console.log() does print()’s job:

Language: JavaScript
  const result = {
    month: "October",
    total,
    rejected,
  };
  console.log(result);

Run on the October export, it logs this:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 The website volunteer wants each rejected row kept whole. So Joan gathers one result, the month, the total and the rejected list, and checkRows() now gives each entry its line, its row and the reason.

00:13 In this lesson, you’ll log that fuller result, find out why its rows seem to go missing in the log, and see every level of it.

00:24 In Python, the end of main() builds that dictionary and prints it on one long line, down to each row. The port builds the same object, its keys without quotes, and total and rejected in shorthand, each a key named after its variable.

00:40 Then console.log() does print()’s job.

00:45 Python printed every row. Your turn: pause the video and predict what JavaScript logs for each row.

00:57 Each row shows up as [Object]. Everything else is there; only the four rows look as if they were never stored. Read that way, you’d go back into checkRows() and change code that was right.

01:12 Node’s console.log() shows the top object and two levels of nesting below it: here, the rejected list, then each entry. Anything deeper it writes as [Object], or [Array] for an array, so big data stays readable.

01:28 The data is all there. Log only the rejected list, and the list becomes the top, so each row, now two levels down, shows in full. To see every level, log the result with console.dir() instead.

01:44 Unlike console.log(), it logs only one value, and takes an options object second. Its depth option says how many levels below the top to show, and null, JavaScript’s value for nothing, means no limit.

01:59 Run it, and each placeholder opens up into its row. Without the depth option, console.dir() stops two levels down, as console.log() does.

02:11 Python’s plain pprint matches console.dir() with no depth limit. Node’s console.log() is like pprint with a depth of three, as pprint counts the top as one.

02:22 Where they part: pprint cuts only when you ask. For the JSON as it would be saved, JSON.stringify() with null and 2 does the job, every key in double quotes.

02:37 In Node, [Object] means deeper, not missing. To see every level, log with console.dir() and a depth of null. Next up: Logging Values With Their Names, where you’ll label each value you log, as an f-string’s = sign does in Python, and meet console.table() and console.trace() for debugging.

Become a Member to join the conversation.