FilterObj 对象过滤
将对象键和值过滤到新对象中,详细参考filter-obj。
基本使用
包含指定键
uni.$c.filterObj.includeKeys(obj, keys\|filter)
排除指定键
uni.$c.filterObj.excludeKeys(obj, keys\|filter)
js
const object = {
foo: true,
bar: false
};
const newObject = uni.$c.filterObj.includeKeys(object, (key, value) => value === true);
//=> {foo: true}
const newObject2 = uni.$c.filterObj.includeKeys(object, ['bar']);
//=> {bar: false}
const newObject = uni.$c.filterObj.excludeKeys(object, (key, value) => value === true);
//=> {bar: false}
const newObject3 = uni.$c.filterObj.excludeKeys(object, ['bar']);
//=> {foo: true}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
参数说明
参数名 | 类型 | 说明 |
---|---|---|
obj | Object | 要过滤的简单对象 |
keys | `Array<string | symbol> |
filter() | `(sourceKey: string | symbol, sourceValue: unknown, source: object) => boolean` |