So, I know what I am trying to do I am just not sure if I am doing it right, and hopefully my question describes what I am trying to do.
I have about a dozen arrays that look like this:
var floorStatusAr = ['','','','','','','','disabled'];
var floorStatusSp = ['','','','','disabled','','',''];
var floorStatusSmm = ['','disabled','','','','','disabled',''];
It seemed too redundant to me, so I was hoping there was a better way. This was my attempt:
var floorStatuses = {
AR:['','','','','','','','disabled'],
SP:['','','','','disabled','','',''],
SMM:['','disabled','','','','','disabled','']
I've also tried:
var floorStatuses = {
"AR":['','','','','','','disabled',''],
"SP":['','','','','disabled','','',''],
"SMM":['','disabled','','','','','disabled',''],
Both ways I can get results from
alert(floorStatuses.AR[0]); //alerts "", [7] alerts "disabled"
But in the rest of my code, I need to be able to call these dynamically. To test this I do:
initial = "AR";
alert(floorStatuses.initial[0]);
But I just get an error that floorStatuses.initial
is undefined.
If I could even capture "AR" from the array such as
alert(floorStatuses[0]); //hoping to alert "AR", but it just alerts "undefined"
I could work with that, because then I could run a for loop and compare it with another variable.
I must just have syntax or logic wrong or something. Surely this is possible.
To address this being marked as a duplicate:
If I came across that question in my searching for the solution to this question, it would not have solved my problem. The question in the duplicate does not even use the same type of object as mine and thus it would not explain how I am to call what I am trying to call. One glance at it and I'd move along because my object contains arrays and so looks nothing like the duplicate's.