-4

I have an object 'myObjects':

let myObjects = {
  "obj1":["X1","1.2"],
  "obj2": "2",
  "obj3": "3"
};

I am trying to only remove the X1 from the obj1 section. I have tried doing:

delete obj1[0];

however end up with

 [null,"1.2"]

how do I get rid of the null?

ANON
  • 75
  • 1
  • 9

1 Answers1

0

You are going to remove element from Array not Object. In that case, you can use Array.splice as follows.

let myObjects = {
  "obj1":["X1","1.2"],
  "obj2": "2",
  "obj3": "3"
};

delete myObjects.obj1.splice(0, 1);
console.log(myObjects);
Derek Wang
  • 10,098
  • 4
  • 18
  • 39