Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Linked list with javascript shows [Object] as value instead of serialized object

I am trying to construct a linked list using a Class with JS. Inside my Class I have a function called checkForEmptyNext() which traverses the list and searches for the node with a next: property of null The function should recursively call itself until it finds the correct node

LinkedList

// 10 --> 15 --> 16


class LinkedList {
  constructor(value){
    
    this.head = {
      value: value,
      next: null
    }
    this.tail = this.head;
    this.length = 1;
  }
  append(value){
    if(this.head.next === null){
      this.head.next = {
        value,
        next: null
      }
      this.tail = this.head.next;
      this.length++
    }else{
      this.checkForEmptyNext(value, this.head.next)
    }
  }
  checkForEmptyNext(value, node){

    if(node.next === null){
        node.next = {
        value,
        next: null
      }
      this.tail = node.next;
      this.length++
    }else{
      this.checkForEmptyNext(value, node.next)
    }
  }
}

const linked = new LinkedList(10);
linked.append(5)
linked.append(16)

console.log(linked)

The console.log is showing:

LinkedList {
  head: { value: 10, next: { value: 5, next: [Object] } },
  tail: { value: 16, next: null },
  length: 3 }

Why am I seeing [Object] instead of the actual serialized value?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda