m = [{
city:'Milano',
country:'Italy',
link: 'details.html#42'
},
{
city:'London',
country:'England',
link: 'details.html#10'
},
{
city:'Rome',
country:'Italy',
link: 'details.html#39'
}
];
<table id="table">
<thead>
<tr>
<th>City</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<tb><a href="details.html#42">Milano</a></tb><tb>Italy</tb>
</tr>
</tbody>
</table>
var table=document.getElementById('table');
for(var i=0; m.length; i++){
var city = m[i].city;
var country = m[i].country;
var link = m[i].link;
}
const tbody = document.querySelector('#table tbody');
// или
const [ tbody ] = document.getElementById('table').tBodies;
tbody.innerHTML = arr
.map(n => `
<tr>
<td><a href="${n.link}">${n.city}</a></td>
<td>${n.country}</td>
</tr>`)
.join('');
for (const n of arr) {
const tr = tbody.insertRow();
const a = document.createElement('a');
a.href = n.link;
a.text = n.city;
tr.insertCell().append(a);
tr.insertCell().textContent = n.country;
}
<table id="table">
<thead>
<tr>
<th>City</th>
<th>Country</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
var items = [{
city: 'Milano',
country: 'Italy',
link: 'details.html#42'
},
{
city: 'London',
country: 'England',
link: 'details.html#10'
},
{
city: 'Rome',
country: 'Italy',
link: 'details.html#39'
}
];
var container = document.getElementById("table").getElementsByTagName("tbody")[0];
items.forEach(item => {
var tr = document.createElement("tr");
var cityName = document.createElement('a');
cityName.href = item.link;
cityName.innerHTML = item.city;
var cityColumn = document.createElement('td');
cityColumn.appendChild(cityName);
var countryColumn = document.createElement('td');
countryColumn.innerHTML = item.country;
tr.appendChild(cityColumn);
tr.appendChild(countryColumn);
container.appendChild(tr);
});
</script>