Help for a Javascript exercise with for...of and Join()

Asked

Viewed 1,305 times

-10

Given the following object array:

var usuarios = [
  {
    nome: 'Diego',
    habilidades: ['Javascript', 'ReactJS', 'Redux']
  },
  {
    nome: 'Gabriel',
    habilidades: ['VueJS', 'Ruby on Rails', 'Elixir']
  }
];

Write a function that produces the following result:

O Diego possui as habilidades: Javascript, ReactJS, Redux
O Gabriel possui as habilidades: VueJS, Ruby on Rails, Elixir

Tip: To traverse an array you must use the syntax for...of and to merge values from an array with a separator use the join.

  • 3

    what is your specific doubt? what you have done with your exercise?

  • I’m unable to use the for...of and Join method

  • Eduardo, please don’t take this the wrong way, but it wouldn’t be right for me to post a solution here because you wouldn’t learn. Also because this seems like an exercise and so, the intention is for you to practice. Take a look at this site: https://www.w3schools.com/js/default.asp has a lot of content that will help you. if you have started doing the exercise, put what you already have and the problems that are occurring

  • I’m just not getting the strings together with Join()

1 answer

1


You only need to first scroll through each object in the array usuarios and then print your attributes on the console. To print each user’s skills on a single line, use the method join to join all elements in one String. See below how it would look:

var usuarios = [
    {
      nome: 'Diego',
      habilidades: ['Javascript', 'ReactJS', 'Redux']
    },
    {
      nome: 'Gabriel',
      habilidades: ['VueJS', 'Ruby on Rails', 'Elixir']
    }
]

for (let usuario of usuarios){
    console.log('O ' + usuario.nome + ' possui as habilidades: ' + usuario.habilidades.join(", "));
}

To stay in the format of what you are asking for in the exercise, I passed as parameter of join the separator ", ", so that it has a spacing between the comma and the value.

  • 1

    And the for...of ?

Browser other questions tagged

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