I am working on a function that extracts data from the current path to create an array ([x, y, z, a, b]). This array is then passed into the reduce method to generate a new array of objects. My goal is to pass each value from the initial array into a function that returns an object, and append that object to the new array. However, when I check the results by console.logging 'accumulate', nothing is being printed out. How can I utilize promises to ensure that the results of accumulate are fully displayed?
let accumulate = path.search
.substring(1)
.split("+")
.reduce((acc, val) => {
FetchMovie(val).then((res) => {
acc.push(res);
});
return acc;
}, []);