How to find selected array item in another array?

#1

Hi, I need some help with JavaScript logic here.

  1. I have an Observable array which is filled by a fetch request (products)
  2. From array “products”, I can select an item and add it to array “cart”

When i’m adding items from array “products” to array “cart”, how can I check if the “product” has already been added to array “cart”? This to avoid duplicates.

*Both share the key id_product and both are Observable arrays.
** The way I’m adding the product is with:
cart.add({
id_product: …
})

0 Likes

#2

@albertolopezdev I think you’re thinking of the where condition or flatMap: https://fuseopen.com/docs/fusejs/observable-api.html#where-condition

0 Likes