I have a sub-optimal solution I'm going for that involves traversing arrays and replacing text in a <table>
depending if those values are found. At the moment refactoring the logic that pulls this data is not an option, so here it goes:
I have an array of Department objects that are available to read when my page loads:
[{id: 1, name: "Arts & Sciences"}, {id: 2, name: "Mathematics"}, {id: 3, name: "History"}]
I also have an array of Building objects
[{id: 50, name: "Building 50"}, {id: 62, name: "Building 62"}, {id: 21, name: "Building 21"}]
On my DOM I have a table populated with Department IDs and their corresponding Building IDs
<tr>
<td>1</td> // Arts & Sciences
<td>50</td> // Building 50
</tr>
<tr>
<td>2</td> // Mathematics
<td>62</td> // Building 62
</tr>
<tr>
<td>3</td> // History
<td>21</td> // Building 21
</tr>
I'm wondering if there's a simple-ish way to use the two available arrays I have to replace the values in my table with the correct values of those arrays.
Again, I cannot change the flow of the app to pull the textual values instead, as much as I'd like to.
Any input is appreciated!