やりたいこと
このtagsを
const customers = [
{
lastName: '2f8',
tags: ['VIP', 'male'],
},
{
email: 'a@gmail.com',
tags: ['VIP', 'male'],
},
{
email: 'c@gmail.com',
tags: ['VIP', 'female'],
},
];
↓
重複のないような一次元配列にしたい
['VIP', 'male','female']
解決方法
const customers = [
{
lastName: '2f8',
tags: ['VIP', 'male'],
},
{
email: 'a@gmail.com',
tags: ['VIP', 'male'],
},
{
email: 'c@gmail.com',
tags: ['VIP', 'female'],
},
];
const array = customers.map((el) => el.tags.map((el) => el));
const flatArray = [].concat(...array);
const noDoubleArray = Array.from(new Set(flatArray));