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

155
Vistas
How to add data to an array without push because it returns the length?

Simple. I have this array and I am trying to add a value to it but when I use push it just returns the length of the array after I push the value. I remember finding a way around this with a different function but I cannot remember what it was.

I will give a bit of context:

function submitCommentHandler() {
        firestore.collection("posts").doc(title).update({
            comments: comments.concat(newComment)
        })

        navigate("/all-posts");
    }

There is the function to add a comment, but when I run that function it changes the value of comments in the firestore db to a number instead of the full array. If the value of the comments changes to a number I cannot access the text within the comments.

I decided to just do comments.push(newComment) and then set the comments to comments in the object. I think thats what some people were telling me.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When you use push() to add a value to an array, the value is pushed to the original array.

const values = [1];
const pushValue = values.push(2);

console.log(pushValue); // 2
console.log(values); // [1, 2]

about 4 years ago · Juan Pablo Isaza Denunciar
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