PricingBlog

Update item in an array

  • giantguf-1241462995431723068

    GiantGuf

    1 year ago

    I'm trying to update the last index of an array with data. I want to update the "message" item with the "Response" value but as you can see the returned index is -1 instead of in this case 1. What am I doing wrong?
    1241462995612209313-image.png
  • lucasg-1241465398776430685

    Lucas G

    1 year ago

    That's not how the Last index of node is used. It requires a formula that will search for an item
  • If it is always the very last item in the array
  • You could use the Take last node instead
  • giantguf-1241467461518360606

    GiantGuf

    1 year ago

    Ok, but that didn't help. I have no idea of what I'm doing here so please show me how it works... 😅
    1241467461182685184-image.png
  • lucasg-1241468484588671056

    Lucas G

    1 year ago

    The Set node basically helps you 'rewrite' an item in an array. The value is what you are rewriting it with
  • lucasg-1241468760276205570

    Lucas G

    1 year ago

    If you do not set a direct path to the specific value in the item, it will overwrite the whole thing
  • giantguf-1241469225499889684

    GiantGuf

    1 year ago

    And how do I set the path?
  • lucasg-1241469326310117537

    Lucas G

    1 year ago

    1241469326049939567-image.png
  • You can use an array for the path, similarly to using a Get node
  • Otherwise, you can set the entire object
  • 1241469783384260678-image.png
  • If you overwrite the entire object then you don't have to specify the direct path to the value in the object that you are updating
  • You'd do this if you want to update multiple values for example
  • giantguf-1241474123759095940

    GiantGuf

    1 year ago

    Thanks Lucas, you saved my day! 😀 👍
    👍1