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 |
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}/>
}