数组使用fliter 函数是可以过滤掉的,但是对象的属性怎么过滤呢?
有时候需要剔除少数属性,留下大多数。类似于TS的omit
例子:
let person = {
name:"jack chen",
age:54,
address:'hongkong'
}
let {name,...xiaohong}=person
console.log(xiaohong);
运行结果:
有时候需要选中少数属性。类似于TS的pick
例子:
let person = {
name: "jack chen",
age: 54,
address: "hongkong",
};
let namePerson = (({ name }) => ({ name }))(person);
console.log(namePerson);
运行结果