Skip to content
Advertisement

javascript removey key pairs from an array of objects

I have this javascript function

    function parseTable(table) {
      var headings = [...table.tHead.rows[0].cells].map(
        //heading => heading.innerText
        heading => heading.dataset.dbrow
      );

      obj = [table1.rows[1]].map(mapRow(headings));

      console.log(obj);

      throw new Error("Something went badly wrong!");

    }

obj is logged in Firefox terminal as

Array [ {…} ]
​
0: Object { riga: "NUOVA", nome: "ddddddddd", tel: "fffffffffff", … }
​​
device: "HDD"
​​
id: ""
​​
iscli: "no"
​​
mail: "fffffffffffffff"
​​
nome: "ddddddddd"
​​
prov: "si"
​​
riga: "NUOVA"
​​
tel: "fffffffffff"
​​
<prototype>: Object 

so it looks really like to be an array object

well

I can’t get rid of completely remove these two key: value pairs

id: ""
riga: "NUOVA"

I tried

delete obj.id;
delete obj.riga;

and

delete obj['id'];
delete obj['riga'];

no way

what is weird is that depite the log output

if i try to log e.g. obj[‘riga’] it prints undefined

but as you can see the log of the entire obj says array object

Thank you for any kind hint

Advertisement

Answer

Use delete obj[0].id.

You have an array of objects, not an object, even though there’s only one entry. Hence you would need to delete the property from the first entry, not obj.

Advertisement