-1
const DenseTable=({x,y,table})=> {
 
    return(
      <><tbody>
                  {table.map((item)=>
                    <tr style={{backgroundColor:" #f3f6f9"}}>
                        <td>P{item.priority}</td>
                        <td>{item.Artificial}</td>
                        <td>{item.Natural}</td>
                    </tr>
                    )}
              </tbody> 
    </> 
    </tbody>

instead of item.Artificial, I need to use item.x (x being the prop). what should be the syntax?

2
  • Could you show the structure of your JSON object? Commented Sep 20, 2020 at 12:35
  • You can access like item[x] Commented Sep 20, 2020 at 12:36

1 Answer 1

0

To use a variable you need to write that variable inside big bracket.

const DenseTable=({x,y,table})=> {

return(
  <><tbody>
              {table.map((item)=>
                <tr style={{backgroundColor:" #f3f6f9"}}>
                    <td>P{item.priority}</td>
                    <td>{item[x]}</td>
                    <td>{item.Natural}</td>
                </tr>
                )}
          </tbody> 
</> 
</tbody>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.