Forum Discussion
Just to know, why you want build a variant array and not just using array of object ?
Could you be more precise on target use ?
Because variant usage is slow.
var myMenu = []; var myItem = {}; myItem.path = "menuitem1"; myItem.picture = screenMenu[1].Picture(); myitem.obj = whatever object you want; myMenu.push(myItem); myItem.path = "menuitem2"; myItem.picture = screenMenu[2].Picture(); myitem.obj = whatever other object you want; myMenu.push(myItem);
And you can then access it easily like myItem[0].path -> give you "menuitem1", etc..
P.S. : There are other kind of notation.
This is a 'Value Key Pair' approach, correct? I have tried this but I get an error trying to run it. "TypeError: Cannot read property 'Name' of undefined" while trying to access 'myItem', log.Message(myItem[0].Name, "");
I am testing with cell XY values so I mocked it out this way. I have an Excel sheet that defines which users should see which menu items so I am trying to put arrays together with the menu paths from the spread sheet and feed them into the application.
function Get_Menu_Cell_Test() { var myArray = []; var myItem = {}; myItem.Name = "Name 1"; myItem.X = "0"; myItem.Y = "1"; myArray.push(myItem); myItem.Name = "Name 2"; myItem.X = "1"; myItem.Y = "1"; myArray.push(myItem); myItem.Name = "Name 3"; myItem.X = "2"; myItem.Y = "1"; myArray.push(myItem); log.Message(myItem[0].Name, ""); log.Message(myItem[0].X, ""); log.Message(myItem[0].Y, ""); }