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

205
Visualizações
FInd duplicates on output

I submit some data via AJAX post and when I get receive response I output it via a loop.

$.each(data, function() {
    $("#em").append('<i class="bi bi-pin-map-fill'+(lat == this.lat && lon == this.lon ? " bg-danger" : "")+'"></i> '+this.lat+' '+this.lon);

    let lat = this.lat,
        lon = this.lon;
}

In some case the coordinates I receive could be of the exact same location, so I'd like to be able to mark those duplicates by adding background color. So I've added a condition to check for matches but am blanking how to implement it, since I can't really set the vars at the end of my loop... Need some nudge in the right direction.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I understand correctly what you are trying to do, you could declare a coordinate array before your loop, then in the loop test if the current coordinate is already in the array with includes method.

For example:

const coordArray = [];
$.each(data, function() {
   const isCoordDupli = coordArray.includes(`${this.lat} ${this.long}`);
   $("#em").append('<i class="bi bi-pin-map-fill'+(isCoordDupli ? " bg-danger" : "")+'"></i> '+this.lat+' '+this.lon);

   coordArray.push(`${this.lat} ${this.long}`);
});
about 4 years ago · Juan Pablo Isaza Relatório
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