Over a million developers have joined DZone.

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"]

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}