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

78
Views
Foreach into an array

I'm using vue.js and lodash to go through a list of events and to get the promoted events. I then want to push each event into a new object or array containing a new list of promoted events. However i'm getting new arrays of each of each object instead of getting each object into 1 array

       getPromotedEvents() {
            //get a list of promoted events
             _.forEach(this.events, (eventList) => {
                if(eventList.promote_event){
                    let arr = [];
                    arr.push(eventList)
                    console.log(arr);
                }
            });
        },


this returns [{}], [{}], [{}] instead of [{},{},{}]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think it's because you're reinstating the array inside the loop. Try this:

getPromotedEvents() {
  let arr = [];
  //get a list of promoted events
  _.forEach(this.events, (eventList) => {
    if (eventList.promote_event) {
      arr.push(eventList)
      console.log(arr);
    }
  });
},

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!