I am using forEach() method called from an array in JavaScript. When I write return;
somewhere inside the method which is called for every element in array I return
function addToCart(pizza, size) {
var res = Cart.some(function(cartItem)) {
if(pizzaAndSizeAreTheSame(cartItem, pizza, size)) {
cartItem.quantity++;
updateCart();
//Want go out from addToCart if this return is reached
return true;
}
return false;
});
if(res) {
return;
}
//Don`t want the code run after return;
Cart.push({
pizza: pizza,
size: size,
quantity: 1
});
updateCart();
}