Pricing Blog

[Solve] how to add (sum) number from APi

  • firdaus___-1194390037345861672

    Mr

    1 year ago

    how can i sum number in toddle

    not sure if im doing it right
    1194390037605929091-Screenshot_2024-01-10_051601.png
    1194390038042120272-Screenshot_2024-01-10_051821.png
    1
  • firdaus___-1194390356750508102

    Mr

    1 year ago

    how to add (sum) number from APi 😭
  • lucasg-1194396525451804823

    Lucas G

    1 year ago

    Use the "Add" node
  • Do you need to add only 2 values or will the array ever have more than 2?
  • lucasg-1194396944018186280

    Lucas G

    1 year ago

    If it could have more than 2 values and you want to add every value then use the "Reduce" node instead
  • firdaus___-1194397022061600850

    Mr

    1 year ago

    it will be more than 2, dynamic table
  • lucasg-1194397416976293909

    Lucas G

    1 year ago

    1194397416716255283-image.png
    1
  • firdaus___-1194398679881232397

    Mr

    1 year ago

    1194398679977689118-Screenshot_2024-01-10_055336.png
    🔥1
  • it work.. what a legend.. thank you
  • firdaus___-1194401503268581527

    Mr

    1 year ago

    [Solve] how to add (sum) number from APi
  • lucasg-1194402213917900901

    Lucas G

    1 year ago

    The reduce now is very powerful
  • It can do more than just add numbers, you can use it for different things
  • In the "Formula" input of the Reduce node, you link it to a series of nodes that iterates over each item in the source array, just like with Filter and Map. In the Accumulator you give it the starting value eg 0. On each iteration it gives you the "result" as an option to refer to as the accumulated value to that point. So if you're adding up a value in an array, you'd have an Add node with the "result" as one number and the value from the array that you're totalling up as the other. A bit like saying result = (result + ThisValueInTheArray) as you would in code. I'll pop a screenshot of an example in a sec.
  • Thanks to @ for that write up a while back of the reduce node!
  • lucasg-1194402866354454728

    Lucas G

    1 year ago

    And thanks for marking it as [Solved]. It's great that people have started doing that