arr1 = ['a', 'b', 'c'] ;
arr2 = ['1', '2', '3', '4'];

我期望
// run time
    query() {
      stuff1 = a;
      stuff2 = 1;
    }
    query() {
      stuff1 = a;
      stuff2 = 2;
    }
    query() {
      stuff1 = a;
      stuff2 = 3;
    }
    query() {
      stuff1 = a;
      stuff2 = 4;
    }
    query() {
      stuff1 = b;
      stuff2 = 1;
    }
     query() {
      stuff1 = b;
      stuff2 = 2;
    }
    query() {
      stuff1 = b;
      stuff2 = 3;
    }
    query() {
      stuff1 = b;
      stuff2 = 4;
    }
    ...
    query() {
      stuff1 = c;
      stuff2 = 6;
    }

怎么写代码?
_.map(arr1, (res) => { reutrn _.map(arr2, (res2, res1) => ... } blabla

我没有主意
如果我使用zip With,a:1 b:2 c:3 ...但是我不想要它
谢谢

最佳答案

var arr = _.chain(arr1).map((item) => {
    return _.map(arr2, (item2) => {
       return {
          stuff1: item,
          stuff2: item2
       }
    })
}).flatten().value();


输出:

https://jsfiddle.net/htreL1of/3/

关于javascript - 如何使用lodash编写嵌套的for循环?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50809320/

10-09 19:00