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

188
Vistas
JavaScript: this keyword not working inside of object?

I have this object "names" which holds an array of names, a function to add a name to the array and to make an unordered list of the array. I would expect that "this.names" would refer to the array in question but I keep getting "undefined". When I use "names.names" it works perfectly but inside of the names object, the "this" keyword should work, right? What am I doing/seeing wrong here?

const names = {
    names: ["Kevin", "Joey", "Achmed", "Bob", "Leo", "Hank"],
    addName: name => this.names.push(name),
    toList: listId => {
        this.names.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
        let ul = document.createElement("ul");
        for (let i of this.names) {
            let li = document.createElement("li");
            li.innerHTML = i;
            ul.appendChild(li);
            document.getElementById(listId).appendChild(ul);
        }
    }
};
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