Given the following object:
var pessoa = {
nome: 'Fernando',
idade: 15,
}
I would like to know what is the most RIGHT way (if there is a more correct way) to remove one of these attributes.
Given the following object:
var pessoa = {
nome: 'Fernando',
idade: 15,
}
I would like to know what is the most RIGHT way (if there is a more correct way) to remove one of these attributes.
You can use delete operator :
var pessoa = {
nome: 'Fernando',
idade: 15,
};
// verifica se nome existe
if (pessoa.nome)
delete pessoa.nome;
console.log(pessoa);