Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!