Javascript class method returning array but not assigning it to a new variable

58 Views Asked by At

I have the following code

var Datos = function(){
    this.salas  = ['something','other'];
}
Datos.prototype.getSalas = function(){
    return this.salas;
}

Then, If I do

var datos = new Datos();
var myArray = datos.getSalas();

Why "myArray" var is now a function and not an array?
How can I convert to an array this variable?

1

There are 1 best solutions below

2
On BEST ANSWER

Works for me:

var Datos = function(){
    this.salas  = ['something','other'];
}
Datos.prototype.getSalas = function(){
    return this.salas;
}

var datos = new Datos();
var myArray = datos.getSalas();

console.log(myArray);

https://jsfiddle.net/v558tzbj/