Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by djechlin, apsillers Sep 11 '14 at 16:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Where is the JSON? –  Teemu Sep 11 '14 at 16:12
1  
@Teemu obj is the json object –  Sharun Sep 11 '14 at 16:13
    
This isn't a JSON array, this is JavaScript array. –  cdhowie Sep 11 '14 at 16:13
2  
Nope, it's a JavaScript object, it has nothing to do with data interchange formats. –  Teemu Sep 11 '14 at 16:13

1 Answer 1

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.