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
  • 857,932
  • 118
  • 1,152
  • 1,264
Sharun
  • 2,892
  • 6
  • 27
  • 58

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
  • 57,408
  • 33
  • 153
  • 271