Group to Category Conversion
var Auto = ['new_auto', 'add_auto'];
//more category objects
var categories = [Auto, Fire, Health, Life, Bank];
function groupToCat(group) {
for (x = 1; x < categories.length; x++) {
for (i = 1; i < categories[x].length) {
if (group == categories[x][i]) {
return categories[x]
}
}
}
}
I'm trying to use a loop within a loop in combination with a multi-dimensional array to achieve a neat conversion function from a group (string new_auto
) to a string equal to the name of the category containing it (array object Auto
).
But as it is, I'm returning the category object, not its name. How can I do this?