title: How to filter out items that were not previously added to an array in React Native?
body: <p>Whenever a user does a product search in our app we need to cache the search results in local storage so that when they are offline and they perform a search it can pull up previously searched items.  With each new search we need to only add the new items to the searchCache.  So if they search for 'be' first then search for 'b' there will be overlapping results but we don't want to add items that are already stored.  This is currently not working though because it still returns all of the items in the search instead of filtering them. Does anyone know how to achieve this?</p>
  
  <p>I want to filter the searchResults by their ids.   Comparing ids to return the items that have ids that are not already in the searchCache.</p>
  
  <pre><code>newItems = searchResults.filter((searchResult) =&gt; {
      return searchCache.find(searchCacheItem =&gt; searchCacheItem.id !== searchResult.id);
  });
  </code></pre>
  
  <p>Here is the entire action function:</p>
  
  <pre><code>export function handleProductSearch(searchTerm) {
      return (dispatch, getState) =&gt; {
          return dispatch(getProductList(searchTerm)).then((results) =&gt; {
              const searchResults = results.items;
  
              // Get previously stored product search cache
              AsyncStorage.getItem(STORAGE_KEY_PRODUCT_SEARCH_CACHE).then((results) =&gt; {
                  return JSON.parse(results);
              }).then((response) =&gt; {
                  const searchCache = response || [];
                  let newItems = [];
  
                  if (searchCache.length &gt; 0) {
                      // Check for duplicates in the recently added items.  Only add the items that are new and not already in the searchCache.
                      newItems = searchResults.filter((searchResult) =&gt; {
                          return searchCache.find(searchCacheItem =&gt; searchCacheItem.id !== searchResult.id);
                      });
                  }
  
                  searchCache.push(newItems.length &gt; 0 ? newItems : searchResults);
                  AsyncStorage.setItem(STORAGE_KEY_PRODUCT_SEARCH_CACHE, JSON.stringify(searchCache));
              }).catch(err =&gt; {
                  console.log('Error retrieving product search cache: ', err);
              });
          });
      };
  }
  </code></pre>