1someValues.forEach((element, index) => {
2 console.log(`Current index: ${index}`);
3 console.log(element);
4});
1const products = [
2 { name: 'laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
3 { name: 'phone', price: 700, brand: 'Iphone', color: 'golden' },
4 { name: 'watch', price: 3000, brand: 'Casio', color: 'Yellow' },
5 { name: 'sunglass', price: 300, brand: 'Ribon', color: 'blue' },
6 { name: 'camera', price: 9000, brand: 'Lenovo', color: 'gray' },
7];
8//Total Products Price by Using forEach
9let totalPrice = 0;
10products.forEach(product => {
11 totalPrice += product.price;
12})
13console.log(totalPrice);
14//Expected output: 45000
1someValues.forEach((element) => {
2 console.log(element);
3});
4
5OR
6
7someValues.forEach((element, index) => {
8 console.log(`Current index: ${index}`);
9 console.log(element);
10});
11