My goal is to have a object like below:
var attrs = {
price : [0, 500000],
housesize : [0, 40],
lotwidth : [0, 30],
storeys : 'both',
bedroom : 0,
bathroom : 0
};
But I dont want to hard code this and would like to generate automatically from the elements of another object. The object looks like this:
var Defaults = {
steps : [10,3,3], // steps for the slider to jump
filters : {
rangeFilter : ['price', 'housesize', 'lotwidth'], // list of slider inputs
radioFilter : ['storeys'], // list of radio inputs
increamentFilter: ['bedroom', 'bathroom'],
}
};
So I am trying to build an object whose keys will be all the values of the filters object. The reason I want to do this is because if I add some value to the filters object, I would not need to create a key in attrs object. The numbers of keys in the attrs object is exactly same as the elements in filters object.
Any help would be appreciated. Cheers.
==========================================
******** EDIT ********
This is what I came up with at the moment
var attrs = {};
for (var key in Defaults.filters) {
var obj = Defaults.filters[key];
for (var prop in obj) {
attrs[obj[prop]] = 0;
}
}
But at the moment I am adding 0 to all the keys of the new element. I need to come up with a way to add specific values to it dynamically. May be another object inside range filter ??
I always use this snipped for such tasks:
from: http://snipplr.com/view/15407/