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

136
Views
Merge multiple outputs from multiple functions into one array in Javascript?

Example

I have these values, there is any way to put them together in a single array?

This is one of the functions that make the results, they take their data from a database.

function AddvotoTec(votor) {
  class Avg {
    constructor() {}
    static average(votor) {
      var total = 0;
      var count = 0;
      jQuery.each(votor, function(index, value) {
            total += value;
            count++;
      });
      return total / count;
    }
  }
  var mvoti = Avg.average(votor);
  voti(mvoti);
}

function voti(Voti) {
  var voti = [];
  voti.push(Voti);
  console.log(voti);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your problem is you put var voti = [] in the function that will initialize a new array every time you call it. If you want to push data to that array, you should move it out from voti(Voti) function

function AddvotoTec(votor) {
  class Avg {
    constructor() {}
    static average(votor) {
      var total = 0;
      var count = 0;
      jQuery.each(votor, function(index, value) {
            total += value;
            count++;
      });
      return total / count;
    }
  }
  var mvoti = Avg.average(votor);
  voti(mvoti);
}

var voti = []; //move the array to the outer scope
function voti(Voti) {
  voti.push(Voti);
  console.log(voti);
}
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!