Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
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 answers
Answer question

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 Report

0

Try this syntax:

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!