Use string variable result as sub path; no code.

Options
I have a string variable.

I'd like to use that string value as the subpath of a variable in an "update variable function"

Can I do this somehow in Xano?

I need it to look something like this in no code, where I can use the result of foo as the sub path of module.

var foo = "bar";
$var.module[foo] = "something else";
// this would be the same as $var.module.bar = "something else"

(this is what I tried in Lambda, ^^ but I cannot update variables from inside the lambda function)

My use case: I'm looping looping through an array that has the keys to indicate what fields need updated. I need to then use that key on the subpath to set the variable. 

Comments

  • Kevin Wasie
    Kevin Wasie Member
    Options
     Thanks for all your help. Maybe this screen shot below will help clarify what I'm wanting to do.

    this is in a for loop with

    array = ["a","b","c"]

    for each fooBar in array {[Screen Shot 2022-04-21 at 10.51.35 AM.png]}

    1) I do not know what the subpath is going to be that I need to update. It is stored in a variable as a string. In this case, called fooBar. 

    2) I then need to get the input with the name of the string value in fooBar.

    I think I can figure out how to do the second step by creating an object, and possibly looping through, if I can figure out how to do the top part of setting the existing variable. 
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    Sounds like you may need the get and set filters. Each of them reference the root object and then you use dot notation (which can be from a variable) to either retrieve an element or set the object at the specified path.