在JavaScript中逻辑与两个布尔数组? [英] Logical anding two boolean arrays in javascript?

查看:70
本文介绍了在JavaScript中逻辑与两个布尔数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ES6中将两个布尔数组相加的和好的优雅的功能性解决方案是什么?

What would be a nice elegant functional solution for anding two boolean arrays in ES6?

const a1 = [true, false, false]
const a2 = [true, true, false]

应导致:

[true, false, false]

推荐答案

使用可以使用

Use can use Array#map to iterate the 1st array, and get the value of the 2nd array using the index (the 2nd param in the callback):

const a1 = [true, false, false]
const a2 = [true, true, false]

const result = a1.map((b, i) => b && a2[i]);

console.log(result);

这篇关于在JavaScript中逻辑与两个布尔数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆