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

137
Visualizações
Compare two array with same fields => if value is different highlight in html table

I have two set of array as response from an API, For example the server response is

let original= [ {firstVal:'1.2'},{SecondVal:'3.2'}];

let latest= [{firstVal:'1.2'},{SecondVal:'4.2'}]

the table will display value from latest array and logic is different value should be highlighted in bold

| Col1 | Col2 |
| 1.2 | 4.2 |

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

0

Let's say you're rendering a table. I'm assuming that's how visualizing this data would make sense.

Then you'll store your first response and store it as its and render the default table

Now when you get your latest response. You'll start comparing row and then column wise if there is difference then the rendered value should be surrounded with a tag to make it bold. Here's a rough code

Assuming a react app


function RenderRow({row, index, latest}){
  if(latest.length < index) {
     console.log("This should not be possible")
     return null
  }

  return <tr>
  {
    row.map((column, c_index) => {
      if(latest[index][c_index] === column){
         return <td>{column}</td>
      }
      return <td><b> {column} </b></td>
    })
  }
  </tr>
}


function TableBody({original, latest}) {

  return <tbody>
   {
      original.map((row, index) => 
         <RenderRow row={row} index={index} latest={latest}/>
      )
   }
  </tbody>
}

function RenderAll(){
  let original= [ {firstVal:'1.2'},{SecondVal:'3.2'}];

  let latest= [{firstVal:'1.2'},{SecondVal:'4.2'}]
  return <Table latest={latest} original={original}/>
}
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