1

I want to delete object from my array posted below but nothing works. If I delete the properties it just goes to undefined. I have a recursive function that returns to me the right object. I wish to delete the second object and his children.

var data = {
        parameters: [
            {
                id: 0,
                name: "First",
                value: "1",
                children: []
            },
            {
                id: 1,
                name: "Second",
                value: "2",
                children: [
                            {
                        id: 2,
                        name: "Third",
                        value: "3",
                        children: []
                    }
                ]
            }
        ],
        index: 3
    }
S Kostrun
  • 19
  • 6

1 Answers1

1

You could use Array#splice.

The splice() method changes the content of an array by removing existing elements and/or adding new elements.

data.parameters.splice(1, 1)
//              index //  \\ length
Nina Scholz
  • 323,592
  • 20
  • 270
  • 324