1

I have an object like this:

  {
    first_name: "acasc"
    last_name: "acsac"
    email: "acac"
    mobile_number: "acac"
    password: "acac"
    confirm_password: "acac"

   }

here is my requirement:

if the password and confirm password matches I have to delete the confirm_password. how can I do that.

1
  • delete obj.confirm_password Commented Feb 6, 2020 at 6:36

2 Answers 2

1

You can simply use delete object.key.

Check the MDN documentation Documentation

In your case,

var data =  {
        first_name: "acasc",
        last_name: "acsac",
        email: "acac",
        mobile_number: "acac",
        password: "acac",
        confirm_password: "acac"
       };
       
      console.log('without delete', data);
      if(data.password === data.confirm_password) delete data.confirm_password;
      console.log('after delete', data);

You can use

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

Comments

1

You can do that this way

let obj =  {
          first_name: "acasc",
          last_name: "acsac",
          email: "acac",
          mobile_number: "acac",
          password: "acac",
          confirm_password: "acac"
         }
         if(obj.password === obj.confirm_password){
           delete obj.confirm_password;
         }
         console.log(obj);

Comments

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.