Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Total shopping amount from an object in javascript

const cart = [
    { name: "laptop", price: 43000, quantity: 1 },
    { name: "shirt", price: 500, quantity: 10 },
    { name: "watch", price: 3680, quantity: 3 },
    { name: "phone", price: 55000, quantity: 1 }
]

let total = 0;
for (const product of cart) {
    const productTotal = product.price * product.quantity;
    total = total + productTotal;
}
console.log(total);
//Output: 114040
Comment

PREVIOUS NEXT
Code Example
Javascript :: limiting the length of dynamic text inside html element 
Javascript :: concatenation mathematics notation 
Javascript :: i wanted to detect when a user enters an alphabet key in input text javascript 
Javascript :: stop React Ant Design Upload component from posting files automatically 
Javascript :: dll node cration 
Javascript :: cant resolve module after typescript install 
Javascript :: jquery image onerror not working 
Javascript :: js object percorrer 
Javascript :: mongoose post new document 
Javascript :: online python to c++ converter 
Javascript :: common library for .net and node js for encryption 
Javascript :: react modal scroll 2 overlapping components 
Javascript :: Make a ReactNative component take the height and width of the current window 
Javascript :: how to return many promises in axios 
Javascript :: how can i use two api at the same time in angular 
Javascript :: mreact graph 
Javascript :: jquery confirm dialog yes no 
Javascript :: how get value of datePicker in react 
Javascript :: template.json exlude files from generating 
Javascript :: functional-javascript-workshop solutions 
Javascript :: simple promise 
Javascript :: express static page 
Javascript :: nodejs Websocket chat room 
Javascript :: can not found jstl core xml file 
Javascript :: javascript const scope = await angular.element(document.body).scope(); 
Javascript :: TextInputEditText click event 
Javascript :: route methods 
Javascript :: typeorm caching queries 
Javascript :: last iteration is for loop js ES6 
Javascript :: api dfetch data in reactjs 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =