所以我想混合一堆我的数组。

例如,如果我有:
array1 = ["Banana", "Orange", "Apple", "Mango"];



array2 = ["Saab", "Volvo", "BMW"];

我想得到

array3 = ["Banana Saab", "Banana Volvo", "Banana BMW", "Orange Saab", "Orange Volvo", "Orange BMW", "Apple Saab", "Apple Volvo", "Apple BMW", "Mango Saab", "Mango Volvo", "Mango BMW"]

好吧,我已经在python上完成了它,但是我很难理解如何在响应时执行它。

这就是我在python上的样子。它看起来很乱,但是效果很好并且很快:

        first_handle = [i for i in combination.first_column.split('\n') if i] or "'"
        second_handle = [i for i in combination.second_column.split('\n') if i] or "'"
        third_handle = [i for i in combination.third_column.split('\n') if i] or "'"
        fourth_handle = [i for i in combination.fourth_column.split('\n') if i] or "'"
        fifth_handle = [i for i in combination.fifth_column.split('\n') if i] or "'"
        sixth_handle = [i for i in combination.sixth_column.split('\n') if i] or "'"
        seventh_handle = [i for i in combination.seventh_column.split('\n') if i] or "'"
        eighth_handle = [i for i in combination.eighth_column.split('\n') if i] or "'"
        itog = ['{} {} {} {} {} {} {} {}'.format(x1, x2, x3, x4, x5, x6, x7, x8)
                for x1 in first_handle for x2 in second_handle for x3 in third_handle
                for x4 in fourth_handle for x5 in fifth_handle for x6 in sixth_handle for x7 in seventh_handle
                for x8 in eighth_handle]
        new_itog = set(itog)


那么我有什么解决方案吗?

我不要求您为我编写代码(但如果您:D我会很高兴)

但是,您是否知道任何示例或项目可以帮助我找到解决方案?

最佳答案

这与反应无关。这是一个简单的数组迭代。


const array1 = ["Banana", "Orange", "Apple", "Mango"]
const array2 = ["Saab", "Volvo", "BMW"]
const results = []

for(let item of array1){
    for(let subitem of array2){
        results.push(`${item} ${subitem}`)
    }
}

console.log(results)

关于javascript - 如何使数组在react-redux上混合?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57075858/

10-10 12:52