let storeProducts = [];
let fetchCalls = [];
// Change i value a/to product total you have 250*6
for (let i = 1; i <= 6; i++) {
fetchCalls.push(fetch('/products.json/?limit=250&page=' + i));
}
Promise.all(fetchCalls)
.then(responses => Promise.all(responses.map(response => response.json())))
.then(productsArray => {
// Flatten the array of arrays into a single array
storeProducts = productsArray.flat();
storeProducts.forEach(productsObj => {
if (productsObj.products) {
productsObj.products.forEach(product => {
console.log('Match found for product with title:', product);
});
} else {
console.log('Invalid products structure in storeProducts');
}
});
})
.catch(error => console.error('Error:', error));