Linked Questions
68 questions linked to/from Better way to sum a property value in an array
9
votes
5
answers
27k
views
How to sum value of two json object key? [duplicate]
"bills": [
{
"refNo": 17,
"billDate": "1-apr-2016",
"dueDate": "30-apr-2016",
"pendingAmount": ...
2
votes
2
answers
3k
views
How to iterate over objects in array and sum a property without iterating? [duplicate]
Is it possible to add up all duration values of an object array without iteration?
const data = [
{
duration: 10
any: 'other fields'
},
{
duration: 20
any: 'other fields'
}
]
...
2
votes
2
answers
2k
views
Getting the Sum of a Particular Field for the Objects in an Array in JavaScript [duplicate]
I know I can use reduce to sum the numbers of an array, like so:
let numArray = [1, 2, 3, 4].reduce((a, b) => a + b, 0);
console.log(numArray);
However, if I have an array of objects, of which one ...
0
votes
4
answers
2k
views
How to iterate through an array of objects and add up the properties [duplicate]
Below is a sample array of objects :
[{Name : Deji, Age: 12}, {Name : Sonia, Age 13}, {Name : Fabio, Age: 21}]
How do I iterate through the arrays in such a way as to add up the ages of the people in ...
0
votes
3
answers
1k
views
Javascript, I need to convert a for loop to .reduce for an array of objects [duplicate]
I'm learning the reduce method and I am trying to use it on this array of objects but i cant seem to figure it out here. the objective is to add all of the age elements together, I can do it with a ...
-2
votes
2
answers
1k
views
How can I show the number of items inside a shopping cart? [duplicate]
I have a shopping cart in one of my projects about e-commerces, and I want to show in the side of the cart icon the number of items on it. There's so many ways to make it, but honestly my brain is so ...
0
votes
1
answer
564
views
How can I find the sum of of Similar array object values and separate them based on their values [duplicate]
I have the following array object
[{ count: 2, created_data: "2022 07 19" },
{ count: 4, created_data: "2022 07 19" },
{ count: 4, created_data: "2022 07 19" },
{ ...
0
votes
2
answers
1k
views
sum of an array using angular for each [duplicate]
function dialogController(generate, $scope) {
$scope.profiles = generate.get_keys('::role');
$scope.content = {};
$scope.options = [];
$scope.servers = {};
$scope.subs = {};
$scope.discountList = {};
$...
-1
votes
4
answers
129
views
Replace FOR to add all values in an array [duplicate]
I'm using Javascript, and I have an array like this:
counters: [
{ id: 1, value: 0 },
{ id: 2, value: 10 },
{ id: 3, value: 5 },
{ id: 4, value: 3 }
]
I want to get a ...
0
votes
3
answers
699
views
Show total sum value of the id from API [duplicate]
Goal:
Display the total sum of all id value after the text "Total sum of all id value is:"
The id value is from the API data.
Problem:
I do not know how to do it and is it possible to do it?
...
1
vote
1
answer
675
views
Get sum of property values within array of objects [duplicate]
I am trying to get an object as output using JavaScript reduce function. It's working, if I define an object {ageTotal: 0} as the second argument. How can I implement this sum of age without defining ...
0
votes
1
answer
468
views
Calculate array subtotals by category [duplicate]
I have an array:
const expenses = [
{ key: '1', sum: '100', category: 'car' },
{ key: '2', sum: '200', category: 'food'},
{ key: '3', sum: '300', category: 'furniture'},
...
0
votes
6
answers
489
views
Add JSON array element for same ID using javascript [duplicate]
I parsed data to a variable
var Mydata = [
{
count: 4,
min: 0,
max: 0,
mean: 0,
ID: 1
},
{
count: 12,
min: 0,
max: 0,
mean: 0,
ID: 2
},
{
count: ...
0
votes
2
answers
439
views
Use a reducer with an object that have a variable key name [duplicate]
The problem was:
const arr = [
{ name1: 'value1', qty: 1, time: 1 },
{ name1: 'value2', qty: 1, time: 2 },
];
// using this reducer works!
const reducer = (acc, { name1, qty}) => {
const ...
-1
votes
1
answer
73
views
Add values of object in array - javascript [duplicate]
This is my response data:
var data = [{
'name': 'ragu',
'taxprice': '20'
} {
'name': 'ram',
'taxprice': '20'
} {...