headers = ["no", "car","color","type"]
//json response
resp = [
{"color":"green", "car":"bmw", "type": "suv", "no":"1"},
{"color":"red", "car":"honda", "type": "sedan", "no":"2"},
{"color":"blue", "car":"vw", "type": "truck", "no":"3"},
]
how can i rearrange the object key:val position based on headers array, so that i can render them in a table like so:
| no | car | color | type |
|---|---|---|---|
| 1 | bmw | green | suv |
| 2 | honda | red | sedan |
| 3 | vw | blue | truck |
I need to use resp as below to render in a table:
resp.map((i,k) => (
<tr key={k}>
<td>{i["no"]<td>
<td>{i["car"]<td>
<td>{i["color"]<td>
<td>{i["type"]<td>
<tr>
}))
resp.map( (i,k) => (<tr key={k}> <td>{i["no"]<td><td>{i["car"]<td><td>{i["color"]<td><td>{i["type"]<td><tr>}))literally hard-coded. as you can see the table, it won't be good for UX, if you dont rearrange theresp, if you just dynamically render them.