Stack Overflow на русском Asked on December 25, 2021
Желательно одной строчкой, и с быстрой обработкой, так как записей может быть миллионы.
let items = [
{qty: "5.45"},
{qty: "7.15"},
{qty: "1.85"}
];
let min = Math.min(...items.map(e => e.qty));
let max = Math.max(...items.map(e => e.qty));
let sum = 0; // как получить сумму всех значений ?
console.log(min);
console.log(max);
console.log(sum);
let items = [
{qty: "5.45"},
{qty: "7.15"},
{qty: "1.85"}
];
let min = Math.min(...items.map(e => e.qty));
let max = Math.max(...items.map(e => e.qty));
let sum = 0;
// Сумма элементов массива
items.forEach((item)=>sum+=(+item.qty));
console.log(min);
console.log(max);
console.log(sum);
Answered by ALexander Lead on December 25, 2021
let items = [
{qty: "5.45"},
{qty: "7.15"},
{qty: "1.85"}
];
console.log(
items.reduce((acc, cur) => acc + +cur.qty, 0)
);
Answered by meine on December 25, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP