0

I have the following piece of code:

<tbody>
  {Object.entries(procedures).forEach(procedure => {
    const [key, value] = procedure
      return (
        <tr key={key}>
          <td className="pt-5">{key}</td>
          <td className="pt-5">
           <button type="button" onClick={() => openModal(value, true)}>
          </td>
        </tr>
      )
</tbody>

I can even console.log(value, key), befure the return and it seems right. If I remove the forEach, and change the values/key variables to another thing, it also works. Does someone know what's the problem?

afr
  • 19
  • 6

1 Answers1

4

Array.prototype.forEach(). always returns undefined ,no matter what you return from. it.

Try with map

<tbody>
  {Object.entries(procedures).map(procedure => {
    const [key, value] = procedure
      return (
        <tr key={key}>
          <td className="pt-5">{key}</td>
          <td className="pt-5">
           <button type="button" onClick={() => openModal(value, true)}>
          </td>
        </tr>
      )
</tbody>
Shubham Dixit
  • 9,242
  • 4
  • 27
  • 46