foo1 = 1
foo2 = 2
foo3 = 3
bar1 = 1
bar2 = 2
bar3 = 3
select = function(object, index){
var out = {}
for(var i in object){
if(! object.hasOwnProperty(i)) return out
if(new RegExp(String(index + "$")).test(i)) out[i] = object[i]
}
return out
}
console.log(select(window, 1))
console.log(select(window, 2))
console.log(select(window, 3))