Why does [object] appear in a nested list implementation in javascript?

jdecuirm

i am practicing javascript, and i am creating a single linked list like example, but i'm getting at the last node [object] instead of adding a new node to the list.

This is my code right now, i hope you can help me, maybe my mistake is at the addNode method.

 function Node(value) {
  this.value = value;
  this.nextNode = null;
}

Node.prototype.addNode = function(newNode) {
  function append(node) {
    if (node.nextNode == null) {
      node.nextNode = newNode;
    }
    else {
      return append(node.nextNode);
    }
  }
  return append(this);
}

var firstNode = new Node(5);
var node2 = new Node(3);
var node3 = new Node(4);
var node4 = new Node(8);
var node5 = new Node(1);

console.log(firstNode);
firstNode.addNode(node2);
console.log(firstNode);
firstNode.addNode(node3);
console.log(firstNode);
firstNode.addNode(node4);
console.log(firstNode);
firstNode.addNode(node5);
console.log(firstNode);

this was printed with Node.js

Node { value: 5, nextNode: null } Node { value: 5, nextNode: Node { value: 3, nextNode: null } } Node { value: 5, nextNode: Node { value: 3, nextNode: Node { value: 4, nextNode: null } } } Node {
value: 5, nextNode: Node { value: 3, nextNode: Node { value: 4, nextNode: [Object] } } } Node { value: 5, nextNode: Node { value: 3, nextNode: Node { value: 4, nextNode: [Object] } } }

Evers

Use util.inspect() to investigate the full linked list.

var util = require('util');

console.log(util.inspect(myObject, {showHidden: false, depth: null}));

# alternative shortcut
console.log(util.inspect(myObject, false, null));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does length not appear as a key in an array object?

From Dev

Why does the rendered object appear distorted?

From Dev

Javascript: Added function does not appear on parent object

From Dev

Why does the UI appear different when input is nested inside label

From Dev

Why does AngularJS fail to initialize Select Option (drop list) when ngmodel is used with nested object?

From Dev

Why does Object.assign not appear to work on Safari 8.0.7?

From Dev

Why does a get_squared_range object appear?

From Dev

Why does this nested dropdown list script not work?

From Dev

Why does this nested dropdown list script not work?

From Dev

Why does this character ▯ appear?

From Dev

Why does the spaceship not appear?

From Dev

Why does not appear FloatingActionButton?

From Dev

Making a nested list appear inline

From Dev

Why does this list implementation take more space than stl list?

From Dev

javascript button does not appear

From Dev

In Javascript, why does Object.getPrototypeOf([1,2]) returns an empty list?

From Dev

Why does this immutable doubly linked list implementation overflow the stack

From Dev

Why does this GridBagLayout not appear as planned?

From Dev

Why does this GridBagLayout not appear as planned?

From Dev

Why does /#!/ appear on address bar?

From Dev

Application does not appear on app list?

From Dev

Groups list does not appear in buddypress

From Dev

why object in javascript does not have find method?

From Dev

Why does JavaScript have the Math object?

From Dev

Why does this nested object initializer throw a null reference exception?

From Dev

Why does nested initializer_list cause memory leaks

From Dev

Why does the Output for a MySQL Connecter Query return as a nested list item?

From Dev

Why does Scala allow nested data structures like List or Array

From Dev

Why does nested initializer_list cause memory leaks

Related Related

  1. 1

    Why does length not appear as a key in an array object?

  2. 2

    Why does the rendered object appear distorted?

  3. 3

    Javascript: Added function does not appear on parent object

  4. 4

    Why does the UI appear different when input is nested inside label

  5. 5

    Why does AngularJS fail to initialize Select Option (drop list) when ngmodel is used with nested object?

  6. 6

    Why does Object.assign not appear to work on Safari 8.0.7?

  7. 7

    Why does a get_squared_range object appear?

  8. 8

    Why does this nested dropdown list script not work?

  9. 9

    Why does this nested dropdown list script not work?

  10. 10

    Why does this character ▯ appear?

  11. 11

    Why does the spaceship not appear?

  12. 12

    Why does not appear FloatingActionButton?

  13. 13

    Making a nested list appear inline

  14. 14

    Why does this list implementation take more space than stl list?

  15. 15

    javascript button does not appear

  16. 16

    In Javascript, why does Object.getPrototypeOf([1,2]) returns an empty list?

  17. 17

    Why does this immutable doubly linked list implementation overflow the stack

  18. 18

    Why does this GridBagLayout not appear as planned?

  19. 19

    Why does this GridBagLayout not appear as planned?

  20. 20

    Why does /#!/ appear on address bar?

  21. 21

    Application does not appear on app list?

  22. 22

    Groups list does not appear in buddypress

  23. 23

    why object in javascript does not have find method?

  24. 24

    Why does JavaScript have the Math object?

  25. 25

    Why does this nested object initializer throw a null reference exception?

  26. 26

    Why does nested initializer_list cause memory leaks

  27. 27

    Why does the Output for a MySQL Connecter Query return as a nested list item?

  28. 28

    Why does Scala allow nested data structures like List or Array

  29. 29

    Why does nested initializer_list cause memory leaks

HotTag

Archive