I use an array of object to display data on a dynamic table I create with javascript inside the table, there are 2 button delete and edit when I press the delete I delete the data from the array but for some reason, the data still remains in the table ? can someone give me a clue why?
workers = [{
name: 'Roni',
phone: '0545931252',
nickname: 'RoniBoy',
mail: '[email protected]',
},
{
name: 'Lior',
phone: '0545996452',
nickname: 'LiorBoy',
mail: '[email protected]',
},
{
name: 'Arman',
phone: '0545886452',
nickname: 'ArmanBoy',
mail: '[email protected]',
}
];
function deleteFromList(id) {
workers.splice(id, 1);
console.log(workers);
}
const toAppend = document.getElementById('appendBox');
let markup = '';
for (let x = 0; x < workers.length; x++) {
markup += `<tr>
<td >` + workers[x].name + `</td>
<td>` + workers[x].nickname + `</td>
<td>` + workers[x].phone + `</td>
<td>` + workers[x].mail + `</td>
<td><button onClick="deleteFromList(this.id)" id="` + x + `" class="btn btn-danger">Remove</button> <button class="btn btn-success">Edit</button></td>
</tr>`
}
toAppend.innerHTML = markup;
<table id="appendBox"></table>
+when you are using template literals? Change it to:<td >${workers[x].name}</td>. You only need backticks at the beginning and the end.onClickshould beonclick