Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Having difficulties with adding items to unordered list with javascript

So I'm trying to retrieve data about countries from an Api (https://restcountries.com/v3.1/all) Languages are displayed like this:

languages: {
  afr: "Afrikaans",
  eng: "English",
  nbl: "Southern Ndebele",
  nso: "Northern Sotho",
  sot: "Southern Sotho",
  ssw: "Swazi",
  tsn: "Tswana",
  tso: "Tsonga",
  ven: "Venda",
  xho: "Xhosa",
  zul: "Zulu"
}

my code so far is:

const langs = Object.values(country["languages"]) //create array of languages

 console.log(langs) 
 return ( 
   <ul>
     {langs.map(each => {
//if i add console.log(each) here, it returns all of the languages in console
     <li>
       {each} doesn't display at all
     </li>
   })}
   </ul>
)

If you could tell me what am I doing wrong, I'd greatly appreciate it. Thanks in advance <3

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The issue with your code seems to be that you aren't returning the JSX in the map function.

To fix this, there are two solutions.


1. Use brackets (()) in the callback

The first solution is to use brackets in the callback.

The brackets will make it so that it will return the value passed into the callback.

To use this, you can use the code below.

langs.map((each) => (
  <li>{each}</li>
));

The only difference in this code is that you are returning it straight away, denoted by the brackets.

If you would like to make this a one-liner, you can use this code.

langs.map((each) => <li>{each}</li>);

This will do the same thing; return the JSX in the arrow function.


2. Use the return keyword

The second option is to use the return keyword.

You can use this to return the JSX so that the map function can use it.

Its usage is very simple.

langs.map((each) => {
  return <li>{each}</li>;
});

This simply returns the JSX to the map function for it to use.


In conclusion, the issue is that you aren't returning the JSX in the map function.

There are two solutions for this.

  1. Use brackets in the callback
  2. Use the return keyword
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda