0

I need to remove a property in an object but I don't want null value. For example

var ob={'name':"CIAO",'animal':'DOG','house':'HOUSE'}

for example I want eliminate 'animal'

delete ob.animal;

the new Object is:

{'name':"CIAO",null,'house':'HOUSE'}

I don't want this result I want this:

{'name':"CIAO",'house':'HOUSE'}

Anyone can help me?

Kishor
  • 2,659
  • 4
  • 16
  • 34
Picco
  • 423
  • 2
  • 6
  • 21

1 Answers1

2

Edit (after clarification of the question):

For deleting animal, you need this. It deletes the property animal.

delete ob.animal;

There is no null value in the object.

var ob = { 'name': "CIAO", 'animal': 'DOG', 'house': 'HOUSE' };
delete ob.animal;
document.write('<pre>' + JSON.stringify(ob, 0, 4) + '</pre>');
document.write(ob.animal + '<br>');
document.write(typeof ob.animal);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392