Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

for each loop with arrowfunction

someValues.forEach((element) => {
    console.log(element);
});

OR

someValues.forEach((element, index) => {
    console.log(`Current index: ${index}`);
    console.log(element);
});
Comment

foreach loop js arrow functons

someValues.forEach((element, index) => {
    console.log(`Current index: ${index}`);
    console.log(element);
});
Comment

How does forEach & arrow function works?

const products = [
    { name: 'laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
    { name: 'phone', price: 700, brand: 'Iphone', color: 'golden' },
    { name: 'watch', price: 3000, brand: 'Casio', color: 'Yellow' },
    { name: 'sunglass', price: 300, brand: 'Ribon', color: 'blue' },
    { name: 'camera', price: 9000, brand: 'Lenovo', color: 'gray' },
];
//Total Products Price by Using forEach
let totalPrice = 0;
products.forEach(product => {
    totalPrice += product.price;
})
console.log(totalPrice);
//Expected output: 45000
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native paper modal background 
Javascript :: how to remove property from object javascript 
Javascript :: useeffect react example 
Javascript :: webpack error cannot find module 
Javascript :: reactjs node sass incompatible with ^4.0.0 ^5.0.0 
Javascript :: how to read a file in javascript 
Javascript :: how to read a csv file in nodejs 
Javascript :: react navigation history clear 
Javascript :: hello world in html using javascript 
Javascript :: javascript DOM query selector 
Javascript :: remove special characters in javascript 
Javascript :: message delete discord.js 
Javascript :: api fetch in react js 
Javascript :: json stringify 
Javascript :: get match number array javascript 
Javascript :: uncheck checkbox when another is checked javascript 
Javascript :: remove element from array by name javascript 
Javascript :: discord js lockdown command 
Javascript :: lodash remove multiple items from array 
Javascript :: react date format 
Javascript :: format javascript date 
Javascript :: binary tree implementation javascript 
Javascript :: React Native Starting In Android 
Javascript :: get url parameters javascript 
Javascript :: replace each string by another string javascript 
Javascript :: javasript array indexof 
Javascript :: Contact form tutorial next.js 
Javascript :: javascriopt initialize 2d array with size 
Javascript :: javascript array any 
Javascript :: useref() in react 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =