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 :: js comparison operators 
Javascript :: move element to the top of list javascript 
Javascript :: how to create thumbnail image from video in javascript 
Javascript :: react native dimensions 
Javascript :: javascript disable div 
Javascript :: object methods in javascript 
Javascript :: escaped json to json javascript 
Javascript :: javascript event currenttarget 
Javascript :: react usecallback 
Javascript :: nuxt add plugin 
Javascript :: queryselectorall example 
Javascript :: how to filter array in javascript 
Javascript :: share to gmail from website 
Javascript :: recursive reverse string 
Javascript :: xlsx js 
Javascript :: js add item to array 
Javascript :: checkbox event listeners 
Javascript :: send sms using twilio in node 
Javascript :: google analyics send event 
Javascript :: check if variable is set javascript 
Javascript :: upload file axios 
Javascript :: remove everything from mongodb databaase mongoose 
Javascript :: javascript change video poster 
Javascript :: csv upload with react 
Javascript :: cors problem node js 
Javascript :: hello world in javascript 
Javascript :: make object readonly javascript 
Javascript :: navlink activestyle not working 
Javascript :: import firebase auth react 
Javascript :: show and hide div based on radio button click react 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =