Cannot read Property 'Join' of Undefined

Asked

Viewed 846 times

-1

I want to consult the array of an element that is within a array through a for..of and I want to unite the elements of array with the function join, but I’m getting the error below and I don’t know why.

Error:

Cannot read property 'join' of undefined

Code:

var usuarios = [{
    nome: "Lucas",
    habilidaes: ["JavaScript", "NodeJS", "MongoDB", "HTML", "CSS"]
  },
  {
    nome: "Rafael",
    habilidades: ["JavaScript", "Java", "MySQL", "HTML", "CSS"]
  }
];

function leitorHabilidades(usuarios) {
  for (usuario of usuarios) {
    console.log(
      'O ' +
      usuario.name +
      ' possui habilidade em: ' +
      usuario.habilidades.join()
    );
  }
}

leitorHabilidades(usuarios);

  • 1

    You wrote habilidaes instead of habilidades

1 answer

1


This is due to a typo, you wrote "enabled" instead of "skills" in the first item of the array

In the function also has another problem, you are searching the "name" of each user but defined as "name"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.