javascript - 想要在对象键中的__键之后拆分键并过滤
问题描述
sample = {
name__subcatogary: 'help',
name__Angel: 'sample'
}
想要在 __ key in object 之后对对象进行排序或过滤
我使用了排序和过滤器,但我无法先拆分它并且
this.sample = res.msg.recordset[0];
console.log(">>>>>>>>>",this.sample.split('__')[1].filter())
过滤对象
sample = {
name__Angel: 'help',
name__subcatogary: 'sample'
}
解决方案
Object.keys(sample)
.map(key => ({key: key, fixed: key.split('__')[1], value: sample[key]}))
.filter(item => filterFunction(item.fixed))
.reduce((p, c) => (p[c.key] = c.value) && p, {})
- 拿钥匙
Object.keys
。 map
具有原始键、值和固定键的新对象数组。filter
带有您的 'filterFunction'的数组。- 使用过滤器键创建新对象
reduce
。
推荐阅读
- java - 如何实例化具有带参数的私有构造函数的泛型类
- python - pydotplus 工作不正常,决策树可视化错误?
- android - (实例中缺少 Vulkan 1.0 API)通过 Android Studio 3.5 和 3.6 Canary 9 启动 Android Emulator(Q API 29)时
- apache-kafka - Spring Cloud @StreamListener 消费者未在消费者组中注册 CONSUMER-ID、HOST 和 CLIENT-ID
- c# - lambda中的初始化惰性字段未在多个线程之间重用
- amazon-web-services - 使用参数在 AWS SAM 中动态创建资源名称
- react-native - 为什么我的模态高度占据了屏幕的一半?
- hibernate - 使用它们的 Id 从两个表创建一个表
- python-3.x - Python list() 与 append()
- matlab - 我的卷积码在完全重叠后停止工作。有什么建议么?