Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
JS function removing old properties from object instead of adding to them

I created an object in JS called filterObj like this

var filterObj={};

The problem is that if I add property to the object, it adds but it removes the previous ones. In fact it takes the root filterObj which is empty, not the edited one.

In which I have two functions:

function handleGovernorate(Governorate) {
    if (Governorate === "") {
        return
    }
    else if (Governorate === "all") {
        delete filterObj.governorate;
        handleFilterObj();
        return setFinalLocations(Locations);
    }
    else {
        filterObj.governorate = Governorate;
        handleFilterObj();
    }
}

function handleGovernorate(District) {
    if (District === "") {
        return
    }
    else if (District === "all") {
        delete filterObj.district;
        handleFilterObj();
        return setFinalLocations(Locations);
    }
    else {
        filterObj.district = District;
        handleFilterObj();
    }
}

If I call handleGovernorate("mountLB") it sets the property governorate with value mountLB, but if I then call handleDistrict("2") the function will set a property district with value 2 but with removing the governorate property - why?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda