I have json data for order.expeditionPlaces which is formatted like:
"expeditionPlaces": "Place1, Place2",
I am trying to split this so that it will display each place on a new line and I also need to be able to check if it is null
Place1
Place2
{order.expeditionPlaces.split(",").join("<br />")} threw an error when it received a null value.
I'm not sure what the best approach to this is, I've tried split and join on the object itself and also tried to put it into const Split but it doesn't like this, I'm not sure where it should go within the if statement?
if (this.state.possibleOrders && this.state.possibleOrders.length > 0) {
this.state.possibleOrders.forEach((order, index) => {
possibleOrders.push(<tr key={index}>
<td>{order.orderId}</td>
<td><Button bsStyle="success">{order.sortingTableName}</Button></td>
<td>{Split}</td>
<td>{order.expeditionPlaces.split(",").join("<br />")}</td>
<td>{order.sortingBufferPlaces}</td>
</tr>);
const Split = if (order.expeditionPlaces.length >0) {order.expeditionPlaces.split(",").join("<br />")}}
}
);