I am working with the stripe API to get a list of all used products in my subscriptions. I am going through all subscriptions and adding the used products into an array (or I'm trying to).
I only want to add a product if it has not been added in yet.
router.get('/getusedproducts', asyncHandler(async(req,res,next) => {
var products = [];
for await (const subscription of stripe.subscriptions.list()) {
for (i = 0; i < subscription.items.data.length; i++) {
var prod = subscription.items.data[i].plan.product;
if (!products.includes[prod]){
products.push(prod)
console.log(prod);
}
}
}
res.send(products)
}));
Currently, this piece of code isn't working as intended because I am still seeing the console log all product. Ideally, the check !products.includes[prod]
should prevent that, but it isn't. I've read several discussion here on stack (1)(2)(3)
Not sure exactly how to compare the items in the array to the new ones I'm getting from JSON object to check if exists.
Any help is appreciated.