Skip to content
Advertisement

Map two separate arrays by matching object keys to values

Been scratching my head on this one for an entire evening with no solution in sight.

Put simply

I am querying two arrays from two separate APIs.

They return data in following format:

API 1

JavaScript

API 2

JavaScript

I need to match the object keys from the second API to the name value of playerInfo from first API so a new array is made that is completely flat like this:

JavaScript

Here’s where I am being stone walled at the moment

JavaScript

I suspect I’m not getting very far because I am not properly accessing my second dataset because there is no index that keeps track of which object I am supposed to pair up with corresponding value in the arrays.

Appreciate any help

Advertisement

Answer

You can implement that using Array.map.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement