Javascript 如何删除包含DOM(或id)信息的JSON对象?

Javascript 如何删除包含DOM(或id)信息的JSON对象?,javascript,arrays,json,Javascript,Arrays,Json,我试图删除一个包含表信息的JSON对象 首先,我声明对象为空: let notas = []; 然后,我通过用户交互操作它,并使用所获取的信息创建一个表。在其中一个单元格中,我创建了一个用于访问该行的按钮: function añadirNota() { //DOING THINGS TO COLLECT DATA const notaObj = { id: Date.now(), dh: tiempo(),

我试图删除一个包含表信息的JSON对象

首先,我声明对象为空:

let notas = [];
然后,我通过用户交互操作它,并使用所获取的信息创建一个
。在其中一个单元格中,我创建了一个用于访问该行的按钮:

function añadirNota() {
        //DOING THINGS TO COLLECT DATA
        const notaObj = {
            id: Date.now(),
            dh: tiempo(),
            imp: colorPArray,
            texto: nota
        }
        notas = [...notas, notaObj];
        //CREATING TABLE AND BUTTON
        var table = document.getElementById("tablanotas");
        var row = table.insertRow(1);
        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        var cell3 = row.insertCell(2);
        //INSERT THE BUTTON WITH THE deleteRow() function
        var textoTransformado = notaObj.texto + `<button class='btn' onclick="deleteRow(this)">❌</button>`; 
        cell1.innerHTML = notaObj.dh;
        cell2.innerHTML = importancia;
        cell3.innerHTML = textoTransformado;
}


function deleteRow(r) {
    var h = r.parentNode.parentNode.rowIndex;
    document.getElementById("tablanotas").deleteRow(h);
   
}
但我不知道接下来会发生什么。我可以在一个对象中进行迭代,与
td
元素进行比较,如果它们相等,则删除该对象吗?

在标记中使用ID(“someId”)比使用getElementById函数检索标记信息更容易:

var textoTransformado = notaObj.texto + `<button id="someId" class='btn' onclick="deleteRow(this)">❌</button>`;
var textoTransformado=notaObj.texto+`❌`;

您的问题不清楚。你能再解释一下吗。但我认为这无助于删除对象。好吧,所以我不理解问题,抱歉,我尝试再次阅读。我正在尝试删除带有
d=t.getElementsByTagName(“td”)[0]的信息的对象如果要从数组notas中删除它,请尝试以下操作:通过单击事件传递obj onclick=“deleteRow(notaObj)”,然后在notas.splice(索引,1)上使用带有notas.indexOf(notaObj)的拼接方法。拼接方法返回数组减去项目(如果您还需要删除notas项目,请使用相同的索引减去1再次拼接)
var textoTransformado = notaObj.texto + `<button id="someId" class='btn' onclick="deleteRow(this)">❌</button>`;