Manipulating arrays to extract unique objects and count occurrences

question 1 from https://codereview.stackexchange.com/q/206227/120114

by samonela

JavaScript

const arr = [
    {key1: [{key2: {id: 1, name: 'a'}}]},
    {key1: [{key2: {id: 2, name: 'b'}}]},
    {key1: [{key2: {id: 2, name: 'b'}}, {key2: {id: 3, name: 'c'}}]}
];
//console.log(arr);

// Step 1: Extract meaningful information from original array
//const arrOfArrOfObj = []; /*
const arrOfArrOfObj = arr
    .map(category => category.key1
        .map(subCategory => (
                {
                    id: subCategory.key2.id,
                    name: subCategory.key2.name
                }
            )
        )
    ); // */
/*for (let category of arr) {
	for (let subCategory of category.key1) {
  	arrOfArrOfObj.push(subCategory.key2);
  }
}    
    console.log(arrOfArrOfObj);*/
    const arrOfObj = [].concat(...arrOfArrOfObj);
console.log(arrOfObj);