My function retrieves information from multiple APIs with callbacks to one variable (results):
function combineObjs(callback) {
function partialResult(results) {
callback(results);
};
searchFlickr.searchFlickr(searchTerm, searchCount, searchPage, partialResult);
searchUnsplash.searchUnsplash(searchTerm, searchCount, searchPage, partialResult);
}
combineObjs( function(results) {
console.log(results)
});
Although the data retrieval process seems to be effective, I encounter an issue when requesting 2 results from each source. The returned data appears as follows:
[ { id: 'flkr-13545844805',
link: 'https://www.flickr.com/photos/28596055@N02/13545844805' },
{ id: 'flkr-3474831728',
link: 'https://www.flickr.com/photos/9848951@N06/3474831728' } ]
[ { id: 'us-fRPxHaHwWwk',
link: 'https://unsplash.com/photos/fRPxHaHwWwk' },
{ id: 'us-JXy99waA3Fo',
link: 'https://unsplash.com/photos/JXy99waA3Fo' } ]
I have researched merging arrays in JavaScript, but the information I found pertains to merging separate arrays, requiring the naming of at least 2 arrays to push one into another. In my case, since I only have one array, those methods do not apply.
I have also attempted using a forEach loop to separate each section enclosed in curly braces, but then I face the challenge of comma separation before adding them to another array. I am uncertain about the best approach in this situation. Thank you in advance for any assistance.