I have 2 arrays.
Size = ['Size 0', 'Size 2', 'Size 3']
Cart = ['1', '2', '3'] // 1, 2, 3 = product id
How to get array position with condition size = 'Size 0' and Cart = '2'?
I tried
let id = req.params.id; // id = product_id
let size = req.body.size;
k = req.session.size.findIndex(function(a){
req.session.cart.findIndex(function(c){
return a == size && c == id;
})
});
but it's not working
You have two separate arrays, so you will need to compute two separate indices - one for Size and one for Cart.
let productId = req.params.id;
let size = req.body.size;
const sizeIndex = req.session.size.findIndex(function(testSize){
return testSize === size;
}); // sizeIndex is valid index as long as it isn't -1
const idIndex = req.session.cart.findIndex(function(testId){
return testId === productId;
}); // idIndex is valid index as long as it isn't -1