-1

Basically this is my object:

Object
    data:Array[4]
        0:Object
        1:Object
        2:Object
        3:Object
        length:4
        __proto__:Array[0]
        __proto__:Object

I want to delete 3rd object i,e 2:object

This is what i am doing.

for(var arr in mainObj){
    var index =  Object.keys(mainObj).indexOf(arr);
    if(index == 2)
    {
        delete mainObj[arr];
    }

 }

This is not working. How to achieve this. Finally i should get.

Object
data:Array[3]
    0:Object
    1:Object
    2:Object
    length:3
    __proto__:Array[0]
    __proto__:Object
JJJ
  • 32,902
  • 20
  • 89
  • 102
Loura
  • 109
  • 5
  • 18

1 Answers1

0

Maybe you can try this:

mainObj.data.splice(2, 1);
Li Enze
  • 679
  • 2
  • 5
  • 18