Reorganizing an Array of Objects in Javascript: “Uncaught TypeError: Cannot read property 'push' of undefined”
问题 I have an array of objects, each of which pairs an entry id with a tag id. I'm trying to reorganize this so that I get an object with a single index for each unique entry_id with a corresponding list of the associated tags. Changing this: tags_entries = [ {'entry_id': 1, 'tag_id': 1}, {'entry_id': 1, 'tag_id': 2}, {'entry_id': 2, 'tag_id': 1}, {'entry_id': 2, 'tag_id': 3}, {'entry_id': 3, 'tag_id': 1} ] To This: entries = { 1: { 'tags': [1, 2] }, 2: { 'tags': [1, 3] }, 3: { 'tags': [1] } }