I have Events API on my website, some of the events do not return/display date – there is an empty string(?).
Is there any way to replace it with “Check website” sting in case if it’s empty?
my code:
.fetch(url)
.then((response) => response.json())
.then((response) => {
let data = response.data;
let html = "";
data.forEach((item) => {
html += `
<div class="card" style="width: 18rem;">
<img src=${item.image} alt="img" class="images">
<div class="card-body">
<h5 class="name">${item.name}</h5>
<p class="city">${item.location.address.addressLocality} - ${
item.location.name
}</p>
<p class="date">Date: ${item.startDate.slice(
0,
-14
)} ${item.startDate.slice(11, -8)} </p>
<a href="${
item.location.sameAs
}" target="_blank" class="btn btn-outline-danger">More Info</a>
</div>
</div>
`;
document.getElementById("root").innerHTML = html;
});
Checked google and nothing helped me.