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.
JavaScript
x
23
23
1
function AddvotoTec(votor) {
2
class Avg {
3
constructor() {}
4
static average(votor) {
5
var total = 0;
6
var count = 0;
7
jQuery.each(votor, function(index, value) {
8
total += value;
9
count++;
10
});
11
return total / count;
12
}
13
}
14
var mvoti = Avg.average(votor);
15
voti(mvoti);
16
}
17
18
function voti(Voti) {
19
var voti = [];
20
voti.push(Voti);
21
console.log(voti);
22
}
23
Advertisement
Answer
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
JavaScript
1
23
23
1
function AddvotoTec(votor) {
2
class Avg {
3
constructor() {}
4
static average(votor) {
5
var total = 0;
6
var count = 0;
7
jQuery.each(votor, function(index, value) {
8
total += value;
9
count++;
10
});
11
return total / count;
12
}
13
}
14
var mvoti = Avg.average(votor);
15
voti(mvoti);
16
}
17
18
var voti = []; //move the array to the outer scope
19
function voti(Voti) {
20
voti.push(Voti);
21
console.log(voti);
22
}
23