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

203
Visualizações
Map method in javascript gives a syntax error

I'm experiencing a syntax error on my map function that says:

',' expected

Here is the relevant code:

class Products extends Component {
  constructor() {
    super();
    this.state = {
    cart: []
   }
}
render () {
const { products } = this.props;
return (
  <>
   <thead>
     <th scope="col"><strong>Name</strong></th>
       {
         products.map((product, key) => {
              (product.title)
        }
    </thead>
  </>
  )
 }
}

Thank you in advance for your time!

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

0

You're not returning the value correctly for jsx within a map function. Try this:

{
   products.map((product, key) => (
       <th key={key}>
         { product.title }
       </th>
      ))
 }

Using the parenthesis rather than the curly brackets will treat it as a returned expression. Whereas, if you use curly brackets, you'd need to return the expression (jsx) explicitly, like this:

{
   products.map((product, key) => {
      return (
       <th key={key}>
         { product.title }
       </th>
      )
    })
 }
about 4 years ago · Juan Pablo Isaza Relatório

0

Try this syntax:

 {products.map((product) => (
          <td> {product.title}</td>
        ))}
about 4 years ago · Juan Pablo Isaza Relatório

0

When you map products here

                    {products.map((product, key) => {
                      (product.title)
                    })}

You are not returning anything in the callback function of map. So you should make it to be

                    {products.map((product, key) => (
                      (product.title)
                    ))}

change { to ( , } to ) so the callback function returning product.title

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