PricingBlog

Trouble converting array to an object

  • tomthebigtree-1270419906273345566

    Tom Ireland

    1 year ago

    I cannot remember how to convert an array to an object. I have tried From entries but this results in an undefined and null result.

    Process I have followed:

    1. Take time now and format date to output the time as HH:MM:SS. This outputs a string.
    2. Split the string by :, which produces an array [HH, MM, SS] e.g. ["17","35","30"]
    3. If I try From entries to convert the array to an object, I get an undefined > null result.
    4. To debug, have tried storing the array in variable and then doing From entries in a formula on a span element to see the output.
    5. Output is [object Object], so appears to be working but I cannot see the object result.

    @Max and @Lucas G - FYI seeing as you were helping me out.
    1270419907065937930-Screenshot_78.png
    1270419906680328338-Screenshot_77.png
  • tomthebigtree-1270420295638978745

    Tom Ireland

    1 year ago

    I know I'm missing something obvious as I'm confident I have come up against this before.
  • max.kayr-1270421085833396234

    Max

    1 year ago

    1270421085564965026-image.png
  • The "From entries" wants a key:value pair
  • tomthebigtree-1270613917839790190

    Tom Ireland

    1 year ago

    Thanks for your help on this yesterday, @Max - really appreciated. 🙂

    I was fairly confident that I could set the keys in the object without conditional logic and managed to crack it this morning. Probably many ways to skin a cat here I think but here's what I came up with.
    1270613917609234475-Screenshot_79.png
  • max.kayr-1270615715895971871

    Max

    1 year ago

    That is more elegant, of course!
    🙇‍♂️1
  • tomthebigtree-1270619622676369409

    Tom Ireland

    1 year ago

    In the spirit of sharing, I re-jigged the original variable. It means instead of creating the array in a variable by splitting the time and then creating an object and using the array variable for the values, I just create the object with the keys I want and then do the time split and set the values in the same formula as I know the split will always produce 3 results. So everything is contained in the one variable.
    1270619622437031987-Screenshot_80.png