Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: auto scroll to view react-native 
Javascript :: js object entries 
Javascript :: method chaining in javascript 
Javascript :: instalar bootstrap en react 
Javascript :: useref in functional component 
Javascript :: learn mongodb 
Javascript :: factorial js 
Javascript :: loop through nested json object typescript 
Javascript :: js get each pair of values from an array of objects 
Javascript :: @click vue target 
Javascript :: fizz buzz program in javascript 
Javascript :: get all a elements javascript 
Javascript :: jquery multiple ids same function 
Javascript :: export app react native 
Javascript :: axios node js 
Javascript :: sweetalert question 
Javascript :: check browser 
Javascript :: javascript array flatten 
Javascript :: path module js 
Javascript :: usb react native device not found 
Javascript :: get height webview from url video react native 
Javascript :: react convert excel to json 
Javascript :: javascript loop an array check if a number is even 
Javascript :: node schedule every minute 
Javascript :: search a word and separate in javascript 
Javascript :: local storage for chrome extension 
Javascript :: js event div class adding 
Javascript :: powershell script string show variable 
Javascript :: jquery if is visible 
Javascript :: using hooks with apis 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =