Hi, I have a problem with fn.call () within a method in an object. I have an arrangement that internally has objects, the values of these objects are type and gender.
when making the sentence of victor.listarGustos (tastes) is only returning me ‘books: futurists’ that is to say only the first value of the array is returning me, and what I am looking for is that I get the whole array, type:’ books’, genre: ‘futurists’
type: ‘music’, genre: ‘rap’
Any correction that I must make to my code?
const gustos = [
{tipo:'libros', genero: 'futuristas'},
{tipo:'musica', genero: 'rap'}
]
class User{
constructor(name){
this.name = name
}
listarGustos(arr){
length = arr.length
console.log(arr)
for(let i = 0; i <length; i++){
return function (i){
console.log(`${this.tipo} : ${this.genero}`)
console.log(i)
}.call(arr[i])
}
}
}
const victor = new User("victor")
victor.listarGustos(gustos)