Describe the issue/error/question
Hello ! I am willing to do a simple calculation in code node to sum some values of an input array as below:
[
{
"id": "11422469276",
"properties": {
"amount": "69",
}
},
{
"id": "11410323382",
"properties": {
"amount": "167",
},
}
]
I am willing to sum the amounts of all objects (1,000 approx.)
I am doing this with this simple calculation (where ($(‘HubSpot’).all())) is the object above:
const calculate = (hubspot) => {
let totalAmount = 0;
console.log(hubspot)
hubspot.forEach((obj) => {
totalAmount += Number(obj.json.properties.amount);
console.log(totalAmount.toFixed(0))
});
const object = {"total": totalAmount}
return object;
}
calculate($('HubSpot').all());
I made this because the error message forces us to return an object.
I tried a lot of different return values and none of them are working.
Could you help me fixing this ?
Thank you for your help, and your patience, i am new to this