gpt4 book ai didi

JavaScript 通过数组进行过滤,并且仅根据一个值的匹配返回

转载 作者:行者123 更新时间:2023-12-01 02:23:40 24 4
gpt4 key购买 nike

我有一个对象数组,它们都有一个阶段键,我只想返回与特定阶段值匹配的对象,然后将其他几个键/值映射到最终返回中。这是我到目前为止所拥有的:

phaseToBlocks (toggle, phase) {
this.phaseBlocks = this.$store.state.addresses.salesRepPhases
return this.phaseBlocks
.filter(fiber_phase === phase)
// .map(({id, phase, name, min_number, max_number}) => ({id: id, phase: fiber_phase, name: name, min_number: min_number, max_number: max_number}))
}

当前不会过滤掉任何对象并返回原始对象数组。这是对象数组的片段:

[ { "fiber_phase": "101", "parsed_hash": "1bc7fb114ee10d7cb9cea10693d238b5", "min_number": 400, "max_number": 499, "sales_rep": "164", "id": "abd90d6b-28a8-2be6-d6c1-abd9007aef38", "name": "48TH ST E", "block_minimum": 400, "block_maximum": 498 }, { "fiber_phase": "101", "parsed_hash": "1bc7fb114ee10d7cb9cea10693d238b5", "min_number": 400, "max_number": 499, "sales_rep": "164", "id": "abd90d6b-28a8-2be6-d6c1-abd9007aef38", "name": "48TH ST E", "block_minimum": 401, "block_maximum": 499 }, { "fiber_phase": "103", "parsed_hash": "1e002ef82be950696f9053dc77b621cf", "min_number": 4700, "max_number": 4799, "sales_rep": "164", "id": "a1d58c9c-6ba7-ebc6-8a74-a1d5806e0bcf", "name": "11TH AVE S", "block_minimum": 4700, "block_maximum": 4798 }]

最佳答案

filter() 采用回调函数来检查条件并执行过滤:

return this.phaseBlocks
.filter(item => item.phase === phase);

关于JavaScript 通过数组进行过滤,并且仅根据一个值的匹配返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48993667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com