DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Prototype Objects/array/collector Example
var MyObj={
obj1:{
prop: ['Ð', 'C', 'D', 'E']
},
obj2:{
prop: ['B', 'C', 'D', 'E']
},
obj3:{
prop: ['Ð', 'E']
},
obj4:{
prop: ['D', 'E']
}
}
var newObj = {}
Object.keys(MyObj).each(function(k,v){
MyObj[k].prop.each(function(x,y){
if(typeof newObj[x]=="undefined"){newObj[x]=[]}
newObj[x].push(k)
})
})
Result:
B: ["obj2"]
C: ["obj1", "obj2"]
D: ["obj1", "obj2", "obj4"]
E: ["obj1", "obj2", "obj3", "obj4"]
Ð: ["obj1", "obj3"]





