Reduce of empty array with no initial value

Good Day All,

I have come across a strange issue while updating a dynamic list. The process requires me to some a a total of (Doubles) Values for each object. On mount the logic works flawlessly. however when updating the dates through a date picker and re-retrieving the data from the database i cannot sum up the values of the doubles merely list them. I receive the following error in console.

bundle.js:35 Uncaught (in promise) TypeError: Reduce of empty array with no initial value
at Array.reduce ()
at bundle.js:35:18241
at async Promise.all (/CB411F83-2292-179C-FF6B-D25974153100/32A961CE-FB71-4A06-B46E-E1040B4AE1A3/files/ui-builder/containers/default/index 1)
at async Object.onClick (bundle.js:35:17)

Does anyone have any suggestions.

As always, much obliged.

Kind Regards,
Raymond

Hello @Raymond_Woodley

Could you provide a logic where it happens?

Hello @Dima

On before mount i run this logic and it works flawlessly
image

I then have to date pickers which adjust the where clause, a start and end date. with a submit button.

the same logic works on 18 of the 22 populated fields in the dynamic/list slash repeater. The logic works on the remaining 4 if i remove the sum of list function and just have the values mapped in the the dynamic list.
image
image

image
image

I cant follow how the same logic can work for some and not others.

Kind Regards,
Raymond

Could you print what will return from the Load table object where you caught an error?

bundle.js:33 Uncaught (in promise) TypeError: Reduce of empty array with no initial value at Array.reduce () at bundle.js:33:18776 at async Promise.all (/CB411F83-2292-179C-…ers/default/index 1) at async Object.onBeforeMount (bundle.js:33:17)

(anonymous) @ bundle.js:33
await in (anonymous) (async)
runHandler @ sdk.js:14
useComponentLifecycle @ sdk.js:14
Block @ sdk.js:14
Panel @ sdk.js:14
a.Component @ sdk.js:14
Ch @ sdk.js:14
Ja @ sdk.js:14
bk @ sdk.js:14
ak @ sdk.js:14
Tj @ sdk.js:14
Lj @ sdk.js:14
(anonymous) @ sdk.js:14
r.unstable_runWithPriority @ sdk.js:14
gg @ sdk.js:14
jg @ sdk.js:14
ig @ sdk.js:14
Jg @ sdk.js:14
Oh @ sdk.js:14
(anonymous) @ sdk.js:14
asyncGeneratorStep @ sdk.js:14
_next @ sdk.js:14
Promise.then (async)
asyncGeneratorStep @ sdk.js:14
_next @ sdk.js:14
(anonymous) @ sdk.js:14
(anonymous) @ sdk.js:14
(anonymous) @ sdk.js:14
fk @ sdk.js:14
r.unstable_runWithPriority @ sdk.js:14
gg @ sdk.js:14
Oj @ sdk.js:14
(anonymous) @ sdk.js:14
V @ sdk.js:14
ee.port1.onmessage @ sdk.js:14

I mean response of Load Table object block, you can also find it at Network tab of dev tools.

The error you provide is a result of some operations on this response.

Good day @Dima

The solution was to add a figure 0 to the array if it was empty.

Kind Regards,
Raymond

Hi Raymond,

It doesn’t look very clean. Additionally, you could easily get the sum calculated by the database:
https://backendless.com/docs/rest/data_sum.html

Mark

Thanks Mark,

Will investigate.