Skip to content

Instantly share code, notes, and snippets.

@nishithMobinius
Created May 7, 2020 04:29
Show Gist options
  • Save nishithMobinius/96d8a5a4f01a1ef65a1d9bbbadfbe361 to your computer and use it in GitHub Desktop.
Save nishithMobinius/96d8a5a4f01a1ef65a1d9bbbadfbe361 to your computer and use it in GitHub Desktop.
filtering products
const productsArray =[{ _id:'1' }, { _id:'2' }, { _id:'3' }, { _id:'4' }, { _id:'5' }]
const alreadyAddedProducts = [{ _id:'1', status:'completed' }, { _id:'4', status:'inProgress' }, { _id:'5', status:'inProgress' }]
const op = productsArray.filter(product=>
!alreadyAddedProducts.some(addedProduct=>
addedProduct._id===product._id && addedProduct.status==='inProgress'
))
console.log(op)
@nishithMobinius
Copy link
Author

this filters products array based on status and id of already added products
your output would be this [{ _id:'1' }, { _id:'2' }, { _id:'3' }]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment