-2

I'm trying to validate null values for required columns in an excel sheet and trying to display the result as a table with columns as - row number, null value column names.

Since it is possible for many columns in a row to have null values, I'm storing those columns as an array.

While displaying it in a table, I'm not able to get the comma delimiter in a element.

Any advice to how to display an array with comma delimeters like [a,b,c,--] in a single column abc in a table ?

Presenting a sample code base 

export default function App() {
 const names = ["a", "b","c"];
  return (
    <div className="App">
      <table>
        <thead>
          <th>Names</th>
        </thead>
        <tbody>
          <td>{names}</td>
        </tbody>
      </table>
    </div>
  );
}
This is giving output as 
Names
abc
Expecting output as 

Names
a,b,c
4
  • I recommend you take a look at an answer I have to a similar question: How do I extract an object(array) from an array of objects? Commented May 10, 2021 at 22:20
  • printing on console is different I believe to the html. Commented May 10, 2021 at 22:29
  • It should be fine! Change console.log(...) to return(...). Don't forget that map() must return a value. So, you'll have return(<div>{things.map((thing)=>{return (<b>{thing}</b>);}</div>)}. If that works, I'll post it as an answer. Commented May 10, 2021 at 22:42
  • If it is just an array with letters as strings, you can always convert the array to one string with delimiter using the Array.join(delimiter). For example in your code: <td>{names.join(',')}</td> Commented May 10, 2021 at 22:52

1 Answer 1

0

You can join the array with delimiter in this case it should be ,;

CODESANDBOX

export default function App() {
  const names = ["a", "b", "c"];
  return (
    <div className="App">
      <table>
        <thead>
          <tr>
            <td>Names</td>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>{names.join(",")}</td>
          </tr>
        </tbody>
      </table>
    </div>
  );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.