js 自己手写的小函数
// 根据 key 值,筛选数组
// const arr = [{title: 'Tom', age: 15},{title: 'Bob', age: 26}]
// dataKeyFilter(arr, 'title'), 返回 [{title: 'Tom'}, {title: 'Bob'}]
export const dataKeyFilter = (data, keys) => {
return data?.map(item => {
const obj = {}
for(let i in item) {
if (keys.includes(i)) {
obj[i] = item[i]
}
};
return obj;
});
}