Working with javascript variable arrays -
i'm trying return results each list, using array of variables containing names of lists.
var filters = ["colour", "size", "len", "s_length", "occasion"]; var colour = ["black", "white", "blue", "brown", "gold", "green", "grey", "multi", "nude", "orange", "pink", "purple", "red", "silver", "yellow"]; var size = ["xs", "s", "m", "l", "uk 6", "uk 8", "uk 10", "uk 12", "uk 14", "uk 16", "uk 18+"]; var len = ["maxi", "midi", "mini"]; var s_length = ["sleeveless", "short", "3/4", "long"]; var occasion = ["casual", "party/evening", "work"]; (var h = filters.length; h--;) { console.log(filters[h]) (var = filters[h].length; i--;) { console.log(filters[h[i]]) } } i'm used python, , seems work want, instead of returning array items undefined result filters[h[i]]
what doing wrong here? tia
you cannot reference local variable string in javascript. there no way array in colour if have string "colour".
what can have filters in object ("dictionary" python people):
var filters = { colour: [ "black", "white", "blue", "brown", "gold", "green", "grey", "multi", "nude", "orange", "pink", "purple", "red", "silver", "yellow" ], size: [ "xs", "s", "m", "l", "uk 6", "uk 8", "uk 10", "uk 12", "uk 14", "uk 16", "uk 18+" ], len: [ "maxi", "midi", "mini" ], s_length: [ "sleeveless", "short", "3/4", "long" ], occasion: [ "casual", "party/evening", "work" ] }; then iterate on pick various values.
object.keys(filters).foreach(function(filtername) { filters[filtername].foreach(function(option) { console.log(option); }); });
Comments
Post a Comment