Sorry I am new to Javascript.
I have the following var
array ...
var sections = [
{ key: "SB04", label:"Storage 4 WBA" },
{ key: "SBO4", label:"Storage 4 CT" },
{ key: "CR04", label:"Storage 4 CR" },
];
How can I re-define this array to return the same label once, based on a key that matches the ones in the list, as shown here?
So I've tried to use this version, but it brings back syntax error in Chrome.
var sections = [
{ key: ("SB04","SB04A","SB04B"), label:"Storage 4 WBA" },
{ key: ("SBO4","SBO4C","SBO4D","SBO4TEST"), label:"Storage 4 CT" },
{ key: "CR04", label:"Storage 4 CR" },
];
So something like GetLabel("SB04C")
or GetLabel("SB04TEST")
, will return "Storage 4 CT" only.
Obviously, the GetLabel()
has to be defined. But I am happy just to get an answer on how to re-code the above var
into something that is understood by the browser.
I've tried this but my use of it returns the label more than once...
var sections = [
{ key: "SB04", label:"Storage 4 WBA" },
{ key: "SB04A", label:"Storage 4 WBA" },
{ key: "SB04B", label:"Storage 4 WBA" },
{ key: "SBO4", label:"Storage 4 CT" },
{ key: "SBO4C", label:"Storage 4 CT" },
{ key: "SBO4D", label:"Storage 4 CT" },
{ key: "SBO4TEST", label:"Storage 4 CT" },
{ key: "CR04", label:"Storage 4 CR" },
];
Output for example:
> Storage 4 WBA
> Storage 4 WBA
> Storage 4 WBA
even though I've given my code only a single key - SB04A