面试题答案
一键面试// 定义subItems数组中对象的类型
type SubItem = {
value: number | boolean;
label: string;
};
// 定义外层对象数组中对象的类型
type MainObject = {
id: number;
name: string;
subItems: SubItem[];
};
// 定义函数
function filterNames(arr: MainObject[]): string[] {
return arr.filter(obj => {
return obj.subItems.some(subItem => subItem.value === true);
}).map(obj => obj.name);
}