At present I have a list of conditional statements such as:
if(x = 1) { $(#div).html('A') };
if(x = 2) { $(#div).html('B') };
if(x = 3) { $(#div).html('C') };
if(x = 4) { $(#div).html('D') };
This does the job but isn't very efficient.
I'm trying to take a DRY approach to this but am unsure of how to go about it.
I'm wondering if something similar to the following will work or if there's a better way to achieve this.
var arr = [
[1, 'A'],
[2, 'B'],
[3, 'C'],
[4, 'D']
]
if ( x === arr[any of sub arrays][0]{ // 1, 2, 3 or 4
$('div#').html('[triggered sub array[1]'); // if 1 is triggered, set html content to A, if 2, set html content to B and so on.
}
Is there a term for what I'm trying to describe here so I can look it up?
div#seems like a syntax error, since it implies you're selecting a<div>coupled with a zero-lengthidproperty, and anidmust be both unique and have a length of one, or more, characters.