[Bug?] [Issue #408] How do I change a value in an array?


#1

lets say I have this:
storeEval | new Array (“one”,“two”,“three”) | array

How do I change the value on the second item?

storeEval | storedVars[‘array’][2]=“five” |

doesn’t work


#2

Anyone can give some input, please?


#4

LoL.Have you tried it before posting? :grin:


#5

Here is a code snippet that first fills an array, and then changes a value with
storeEval | storedVars['names'][${num}] = "Hello World!"

{
  "CreationDate": "2018-10-30",
  "Commands": [
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "open",
      "Target": "https://a9t9.com/kantu/demo/storeeval",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "new Array ('cat','dog','fish','dog','??','frog','?','dog','??','horse','??elephant')",
      "Value": "names"
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['names'].length",
      "Value": "length"
    },
    {
      "Command": "store",
      "Target": "2",
      "Value": "num"
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['names'][${num}]",
      "Value": "myrandomname"
    },
    {
      "Command": "echo",
      "Target": "in array is ${myrandomname}",
      "Value": "blue"
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['names'][${num}] = \"Hello World!\"",
      "Value": "myrandomname"
    },
    {
      "Command": "echo",
      "Target": "in array is now ${myrandomname}",
      "Value": "green"
    }
  ]
}

#6

This doesn’t change anything. This is the problem. You just assign $myrandomname a value FROM the array and call it for echo. JavaScript code doesn’t actually work in StoreEval just gets the void.
Check for yourself. Just call it once again. It is fish and always was. Sic!
{
“CreationDate”: “2018-10-31”,
“Commands”: [
{
“Command”: “store”,
“Target”: “fast”,
“Value”: “!replayspeed”
},
{
“Command”: “open”,
“Target”: “https://a9t9.com/kantu/demo/storeeval”,
“Value”: “”
},
{
“Command”: “storeEval”,
“Target”: “new Array (‘cat’,‘dog’,‘fish’,‘dog’,’??’,‘frog’,’?’,‘dog’,’??’,‘horse’,’??elephant’)”,
“Value”: “names”
},
{
“Command”: “storeEval”,
“Target”: “storedVars[‘names’].length”,
“Value”: “length”
},
{
“Command”: “store”,
“Target”: “2”,
“Value”: “num”
},
{
“Command”: “storeEval”,
“Target”: “storedVars[‘names’][${num}]”,
“Value”: “myrandomname”
},
{
“Command”: “echo”,
“Target”: “in array is ${myrandomname}”,
“Value”: “blue”
},
{
“Command”: “storeEval”,
“Target”: “storedVars[‘names’][${num}] = “Hello World!””,
“Value”: “myrandomname”
},
{
“Command”: “echo”,
“Target”: “in array is now ${myrandomname}”,
“Value”: “green”
},
{
“Command”: “storeEval”,
“Target”: “storedVars[‘names’][${num}]”,
“Value”: “myrandomname”
},
{
“Command”: “echo”,
“Target”: “in array is now ${myrandomname}”,
“Value”: “red”
}
]
}


#8

You are right - I see the issue now. To me, that looks like bug, and I made a ticket for it.

{
  "CreationDate": "2018-10-31",
  "Commands": [
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "open",
      "Target": "https://a9t9.com/kantu/demo/storeeval",
      "Value": ""
    },
    {
      "Command": "storeEval",
      "Target": "new Array ('cat','dog','fish','dog','??','frog','?','dog','??','horse','??elephant')",
      "Value": "names"
    },
    {
      "Command": "store",
      "Target": "2",
      "Value": "num"
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['names'][${num}]",
      "Value": "myrandomname"
    },
    {
      "Command": "echo",
      "Target": "in array is ${myrandomname}",
      "Value": "blue"
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['names'][${num}] = \"Hello World!\"",
      "Value": "notused"
    },
    {
      "Command": "storeEval",
      "Target": "storedVars['names'][${num}] ",
      "Value": "newname"
    },
    {
      "Command": "echo",
      "Target": "in array is now ${newname}",
      "Value": "green"
    }
  ]
}