Javascript ES6 - 映射多个数组 [英] Javascript ES6 - map multiple arrays
本文介绍了Javascript ES6 - 映射多个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么像拉链:
var myFn = function(a,b){console.log(a,b);}
var arr1 = ['a','b','c ];
var arr2 = [1,2,3];
arr1.map(myFn,arr2); //虚构语法
//印刷品:
// a 1
// b 2
// c 3
解决方案
不幸的是没有。您要查找的内容通常称为 zip
或 zipWith
。请参阅lodash的实现以获得参考: https://lodash.com/docs#zipWith
Is there a feature in JavaScript 6 that allows to map over multiple arrays ?
Something like a zipper :
var myFn = function (a, b) { console.log(a, b);}
var arr1 = ['a', 'b', 'c'];
var arr2 = [1, 2, 3];
arr1.map(myFn, arr2); // imaginary syntax.
// prints :
// a 1
// b 2
// c 3
解决方案
Unfortunately, no. What you are looking for is commonly called zip
or zipWith
. See lodash's implementation for a reference: https://lodash.com/docs#zipWith
这篇关于Javascript ES6 - 映射多个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文