I have to do the following exercise:
Extend the given class to implement a count () function that prints the number of elements contained in the "value" property in the console. (Do not modify the given constructor)
Instance the class and call the new count function ().
// No modificar este constructor. function Clase (elem) { this.valor = []; this.valor['elem1'] = 1; this.valor['elem2'] = 2; this.valor['elem3'] = 3; this.valor['elem4'] = elem; }
Given this exercise, what I did was:
Clase.prototype.metodo()
{
var a = this.valor.length;
return a;
}
var miClase = new Clase(4);
console.log(miClase.metodo())
But the array length gives me 0; I do not know what I was wrong about, where is the problem and how can I solve it?