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 :: convert arraybuffer to file javascript 
Javascript :: push an property and value to an object in javascript 
Javascript :: jquery check if input is empty 
Javascript :: filter out object in array using two arguments 
Javascript :: bodyparser deprecated vscode 
Javascript :: viewmodelprovider example 
Javascript :: Error: Unable to resolve module ./index from 
Javascript :: set auth header on axios instance 
Javascript :: how to filter out undefined keys from object in js 
Javascript :: function range() as range js 
Javascript :: angular cors issue 
Javascript :: datatable get row data 
Javascript :: dynamic loop variable .each create hash javascript 
Javascript :: how to pass data between components in react 
Javascript :: is a letter javascript 
Javascript :: string to object 
Javascript :: js reverse JSON.stringify 
Javascript :: promise.all async await 
Javascript :: convert string to set in js 
Javascript :: Javascript console log a string 
Javascript :: how to set input date to today date on initialization 
Javascript :: javascript how to get middle letters of a string 
Javascript :: Repeat a String Repeat a String 
Javascript :: chart js change axis label 
Javascript :: data-id html javascript 
Javascript :: set css var with javascript 
Javascript :: sort nested data using sort function javascript 
Javascript :: javascript regex example match 
Javascript :: resize windows 
Javascript :: replace many chracters js 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =