I have a object
{
"id": 1,
"collectionName": "dsa",
"collectionItemsID": [
"ad",
"deneme1"
],
"ownerOfCollection": "117961395738439786389",
"createdAt": "2022-06-16T12:54:52.146Z",
"updatedAt": "2022-06-16T12:54:52.146Z"
}
When I push to front like that in ReactJS
{collection.collectionItemsID}
I am getting output with joined.
addeneme1
It needs to be seperated. I didnt wanted to use javascript for seperate. I need to learn how to do correctly. I think I needs to use Object.keys but I am failed with this way.
How can I map collectionItemsID in ReactJS?
this is the example way of I wanted to implement object outputs
{data.map((item, i) => (
<tr key={i}>
<td>
<input
id={item.user_id}
type="checkbox"
value={item.user_id}
onChange={handleChange}
checked={isChecked}
/>
</td>
<td>{item.user_id}</td>
<td>{item.user_name}</td>
<td className="isbanned">{item.isbanned}</td>
<td>{item.registration_date}</td>
<td>{item.last_login}</td>
</tr>
))}
Solution
<div>
{Object.keys(collection).length > 0 ? <div>
<h1>{collection.name}</h1>
<p>{collection.description}</p>
{collection.collectionItemsID.map(function (itemID) {
return <a href={`/${itemID}`}>{itemID}</a>
})}
</div> : <p>Loading...</p>}
</div>
collectionItemsIDis an array, so what do you concretely want to have happen here? Two<a>elements, one for each string incollectionItemsID? A single<a>with the content of collectionItemsID joined with/? There seem to be details missing here that prevent answering this question.