Reputation: 13
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.
Upvotes: 1
Views: 1177
Reputation: 6130
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
Upvotes: 1
Reputation: 1366
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);
Upvotes: 1