I have two JSON Arrays a and b. a is the array I want to add information to which is contained in b. a and b both have a keyNum which I will be using to match the needed information in b to the relevant record in a.
a is formatted like:
a = [
{
keyNum: ...,
extra: ...
}
]
With elements ordered by `keyNum (with descending ordering).
b is formatted like:
b = [
{
keyNum: ..,
infoNeededIna; ...
}
]
With elements also ordered, but not necessarily descending.
The data in the arrays are JSON strings which I have called from an API. the keyNum is an order number. B is essentially the parent which contains records of A in the database I am grabbing this from. Unfortunately, the info I need in B is not contained in the record of A
I need infoNeededIna
into the a record where ever keyNum
is equal between a and b. a and b have a many to one relationship to so it is likely that keeping track of the index i am looking in b would be much more efficient than starting the search at the first record each time.
I know how I could brute force this but I wanted to see if anyone knew a more elegant solution.
My thoughts now is that I could use a loop through a and use the keyNum
to then pilot an inner loop into b to search for the relevant index of b and grab infoNeededIna
.