lundi 26 novembre 2018

How can I push data into an array?

I pushed some data into an array:

if(target === 'create'){
    if(name === 'form[username]' || name === 'form[name]' || name === 'form[slug]' || name === 'form[plainPassword]'){
        errors.push(name);
    }
} else {
    if(name === 'form[username]' || name === 'form[name]' || name === 'form[slug]' ){
        errors.push(name);
    }
}

It actually works fine. But it seems to me that it is really too much repeating code, but I still cannot find a way to reduce the code, or make a simpler better solution.

Aucun commentaire:

Enregistrer un commentaire