Q:

Distinct values from Array inside Array of objects

Ive got an array of objects.  Inside each object there is another array. 
I want to extract distinct values from these arrays. 

var data = [
            {categorie: 'Stuff', type: 'One', designs: ['A', 'B']},
            {categorie: 'Stuff', type: 'Two', designs: ['C']},
            {categorie: 'Stuff', type: 'One', designs: ['D']},
            {categorie: 'Other', type: 'Three', designs: ['C', 'D']}
        ];
console.log([...new Set(data.map(x => x.categorie))]);
console.log([...new Set(data.map(x => x.type))]);

//expected output for designs ['A','B','C','D']

A:

You can use flatMap() instead of map()

var data = [
            {categorie: 'Stuff', type: 'One', designs: ['A', 'B']},
            {categorie: 'Stuff', type: 'Two', designs: ['C']},
            {categorie: 'Stuff', type: 'One', designs: ['D']},
            {categorie: 'Other', type: 'Three', designs: ['C', 'D']}
        ];

console.log([...new Set(data.flatMap(x => x.designs))]);

//expected output for designs ['A','B','C','D']

If your browser doesn't support flatMap() then you can use concat() with spread operator. 

var data = [
            {categorie: 'Stuff', type: 'One', designs: ['A', 'B']},
            {categorie: 'Stuff', type: 'Two', designs: ['C']},
            {categorie: 'Stuff', type: 'One', designs: ['D']},
            {categorie: 'Other', type: 'Three', designs: ['C', 'D']}
        ];

console.log([...new Set([].concat(...data.map(x => x.designs)))]);

//expected output for designs ['A','B','C','D']

