What is this function in JavaScript? delete

2

I was seeing some javascript code and I came across a function that in one part does something I do not understand, I was searching the internet but it does not show me what I'm trying to find.

function iniciarSesion(correo,password)
{
    let enviar = true;
    var formData = {}; // Objeo que guarda los inputs
    var elementos = $("#formRegistro input");
    let el;

    for(let i = 0; i < elementos.length; i++){
        el = $(elementos[i]); // Elementos del form
        formData[el.attr("name")] = el.val();
    }

    if( formData["correo"] === "" ) delete formData["correo"];
    if( formData["password"] === "" ) delete formData["password"];
}


**Estas lineas son las que no entiendo**

if( formData["correo"] === "" ) delete formData["correo"];

if( formData["password"] === "" ) delete formData["password"];
    
asked by Eric 25.12.2018 в 15:28
source

1 answer

3

that's to erase those properties from the formData vector if it is set first it goes through the inputs of the record and stores them in the formData vector

then validates that if formData ["mail"] is empty then remove formData ["mail"] and do the same with password

for example if I have this vector

 var persona= {
      nombre:"Pedro",
      edad: 32
    };

and I show an alert with age

 alert(persona.edad)

I will see "32" but if I do a delete a person.edad and I do that alert again the message that will come out is " undefined " because that property does not exist

    
answered by 25.12.2018 / 16:23
source