Ask Question

ReactJS: How can I loop in react (JSX)

I want to render an array of data in a <table>. How can I loop the array and render table rows in jsx?



Authorยดs Anki Batsukh image

Anki Batsukh

Last edited on

1 Answer available

Best answer

The most common way is to use [].map() function in order to render the <tr>s directly in return

const YourComponent = () => {
  return (
          {/* <th>... */}
        {(arr || []).map((trData, index) => (
          <tr key={index}>
            {/* <td>... */}
Last edited on