0

How do i remove an empty key value pair from an object like

obj = {name: 'asd','':'',pass: true}

is to be made obj = {name: 'asd',pass: true}

Thanks in advance

asked May 18, 2017 at 16:18
1
  • you are welcome. Thanks for sharing your issue with us. When do you plan to show us what you have tried and where do you get stuck at? Commented May 18, 2017 at 16:20

3 Answers 3

3

Try this delete obj[''];

More about delete operator: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/delete

answered May 18, 2017 at 16:21
Sign up to request clarification or add additional context in comments.

Comments

1

you can simply try :

delete obj[''];
answered May 18, 2017 at 16:21

Comments

1

In one line:

delete obj[''];

or

 for(property in obj){ 
 if(property == ""){
 delete obj[property]
 }
 }
brasofilo
26.2k15 gold badges96 silver badges189 bronze badges
answered May 18, 2017 at 16:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.