I create an object with 3 parameters, and insert it into an array. Now, when I go through the array, I always get undefined
, and I've tried several things, but nothing.
This is my code:
//*************************** Arrays ***************************
//El que va a contener todos los votos, el que recorro que dentro tiene los objetos.
var contenedor = [];
var colegiosPrueba = ["Virgen Pilar"];
var partidos = ["PP", "PSOE", "Podemos", "Ciudadanos", "IU"];
//Por cada colegio, coge un voto de cada partido
function aVotar() {
for (var i = 0; i < colegiosPrueba.length; i++) {
for (var j = 0; j < partidos.length; j++) {
var aux = prompt(colegiosPrueba[i] + "--" + partidos[j]);
voto(colegiosPrueba[i], partidos[j], aux);
contenedor.push(voto);
}
}
}
//Ver array
function verArray() {
for (var i = 0; i < contenedor.length; i++) {
var auxi = parseInt((contenedor[i].getColegio));
}
}
function voto(colegio, partido, numeroVotos) {
this.colegio = colegio;
this.partido = partido;
this.numeroVotos = numeroVotos;
this.getColegio = function(colegio) {
return this.votos[colegio];
}
this.getPartido = function(partido) {
return this.votos[partido];
}
this.getNumeroVotos = function(numeroVotos) {
return this.votos[numeroVotos];
}
}
aVotar();
console.log(contenedor);