0

I am deleting an element from an array using delete

I ave this object:

obj = {
    Variables: [ {
        Name: "test",
        Type: "Int",
        Control: "U",
        Value: "123"
    }, {
        Name: "ftr",
        Type: "DateTime",
        Control: "UA",
        Value: "123123"
    }, {
        Name: "wertwe",
        Type: "Int",
        Control: "SA",
        Value: "435345"
    } ]
};

using this code:

 delete data["Variables"][2];

Now obj contains the value:

{"Variables":[{"Name":"test","Type":"Int","Control":"U","Value":"123"},{"Name":"ftr","Type":"DateTime","Control":"UA","Value":"123123"},null]}

Is there any way to delete an element without a null value appearing in the object?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Sharun
  • 3,022
  • 6
  • 30
  • 59

1 Answers1

0

You punctured a hole in the array. You will need to use splice to remove the hole. I found the dupe after writing this answer so I'm going to vote to close with the Q/A where the example is.

djechlin
  • 59,258
  • 35
  • 162
  • 290