Here is the code in which else does not work, it stands by the standard, that is, when the product is even found, it still executes what is written in the else , what is wrong?
products.forEach(function(e) { if(e.id == id) { document.getElementById('product-name').innerHTML = e.name; document.getElementById('product-miniAbout').innerHTML = e.miniAbout; document.getElementById('product-about').innerHTML = e.about; document.getElementById('product-category').innerHTML = e.category; document.getElementById('product-id').innerHTML = e.id; document.getElementById('product-bigPicture').innerHTML = '<img src="'+ e.img +'" style="max-height: 450px;" alt="'+ e.miniAbout +'">'; document.getElementById('product-picture').innerHTML = '<img src="'+ e.img +'" alt="'+ e.miniAbout +'">'; document.getElementById('product-price').innerHTML = e.price + ' Грн.'; } else { document.getElementById('product-bigPicture').innerHTML = '<img src="https://images.unsplash.com/38/awhCbhLqRceCdjcPQUnn_IMG_0249.jpg?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=9c2c8df6c036962d2ba24fd6af421a40" style="max-height: 450px;">'; document.getElementById('product-about').innerHTML = 'Товар не найден!'; document.getElementById('product-product').innerHTML = '<b>Cheap Shopping</b>'; document.getElementById('delivery').innerHTML = '<b>Cheap Shopping</b>'; } return; });
getElementById. ID must be unique. - Invisionvar found=false; if(e.id==id) { ваши действия когда найдено; found=true; } ПОСЛЕ ЦИКЛА: if(!found) { действия которые когда не найдено }var found=false; if(e.id==id) { ваши действия когда найдено; found=true; } ПОСЛЕ ЦИКЛА: if(!found) { действия которые когда не найдено }- Mike