I need to combine rows and rows2. If either of them don't have a value, their values is "none". How do I combine them? The problem now is that its creating multiple rows that is empty.
Codesandbox CLICK HERE
<TableBody>
{[...(rows || []), ...(rows2 || [])].map((row) => (
<TableRow
key={row.name}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell component="th" scope="row">
{row.name}
</TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
))}
</TableBody>
const a = "none"; console.log(...a)print?console.log("n", "o", "n", "e")rows2always be a string? You are spreading the string in as a character array. Can you clarify what you want to "combine"? From what I can tell you are are iterating one and then iterating the other. Is that all you want to do, or do you want to "merge" any of the row data? Can you provide an example expected output?rowsandrows2will not always be a string. If they have a value they will return to an array, if they don't have a value, they will return to a string "none". I want to combinerowsandrows2to iterate them into the table.rowsandrows2have the same data structure.rowshave values whilerowsreturn "none", then only iteraterowsin the table and vice versa. If both have values of "none", then don't iterate them in the table.