I have a problem with the javascript filter function.
This is my idea of how it should work.
- I need to check if an object is in the fetchedImage array (at first all the images are not in the array because the array is empty).
- so we push all images that are new (not in the fetchedImage array) into the queue array.
- the second time we check if the objects are in the array, they will be in the array so no images go in the queue array.
my code results show that the queue is keeping to grow without adding new images.
my code:
let images = res.items;
if(images)
{
// should return items that are not in the array
let newImages = images.filter(image => {
return fetchedImages.includes(image) == false; // ps: (image is object)
})
// add all new images into the queue array
queue = [].concat(queue, newImages);
}
(I probably did something wrong in the filter function but i cannot fix it)