Answers for "how can we give the index of an array as an ID to an element"

0

how can we give the index of an array as an ID to an element

//Here the delete button gets a unique ID everytime, the ID is the array index of the element. 
array.forEach(function (element, index) {
      display =
        display +
        `<tr>
            <th scope="row">${index + 1}</th>
            <td>${element.first}</td>
            <td>${element.second}</td>
            <td>${element.third}</td>
            <td><button type="button" id="${index}" onclick="deleteNode(this.id)" class="btn btn-danger">Delete</button></td>
        </tr>`;
    });
Posted by: Guest on May-02-2021

Code answers related to "how can we give the index of an array as an ID to an element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language