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?

6
  • possible duplicate: stackoverflow.com/questions/208105/… Commented Feb 22, 2016 at 9:09
  • 1
    delete ob[1]; does not delete anything! Commented Feb 22, 2016 at 9:09
  • You sure delete ob[1]; deletes anything? Commented Feb 22, 2016 at 9:10
  • I don't see this occurring in node, nor in any browser ... what environment is this occurring in for you Commented Feb 22, 2016 at 9:14
  • 1
    o be honest {'name':"CIAO",null,'house':'HOUSE'} is not even a valid object Commented Feb 22, 2016 at 9:15

1 Answer 1

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);

Sign up to request clarification or add additional context in comments.

1 Comment

see edited question - claims that delete ob.animal results in an invalid javascript object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.