gpt4 book ai didi

JavaScript如何同时过滤两个数组

转载 作者:行者123 更新时间:2023-11-28 12:12:50 34 4
gpt4 key购买 nike

假设我有两个数组:

var one = [1,2,3,4,5];

var two = ["A","B","C","D","E"];

如果我要过滤第一个数组,使其返回以下结果:

 var resultOne = one.filter(v => v == 2 || v == 3 );

结果将返回 [2,3] 但我如何根据此结果过滤另一个数组以返回 [B,C]...第一个?

最佳答案

var one = [1,2,3,4,5];

var two = ["A","B","C","D","E"];

var resultOne = two.filter((v,i) => one[i] == 2 || one[i] == 3 );

console.log(resultOne)

关于JavaScript如何同时过滤两个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166692/

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