1

how to combine two-dimensional arrays of several objects that I have like this

const vars = [{
        id: 1,
        values: ['red', 'blue']
    }, {
        id: 2,
        values: ['11', '22', '33']
    }];

Expected results like this, expected data are not the same

    const results = [
        [
            {id: 1, value: 'red'},
            {id: 2, value: '11'},
        ],
        [
            {id: 1, value: 'red'},
            {id: 2, value: '22'},
        ],
        [
            {id: 1, value: 'red'},
            {id: 2, value: '33'},
        ],

        [
            {id: 1, value: 'blue'},
            {id: 2, value: '11'},
        ],
        [
            {id: 1, value: 'blue'},
            {id: 2, value: '22'},
        ],
        [
            {id: 1, value: 'blue'},
            {id: 2, value: '33'},
        ],
    ];
  • Please visit the [help], take the [tour] to see what and [ask]. [Do some research, search for related topics on SO](https://www.google.com/search?q=javascript+all+possible+combinations+two+arrays+site:stackoverflow.com); if you get stuck, post a [mcve] of your attempt, noting input and expected output using the `[<>]` snippet editor. – mplungjan Jul 31 '20 at 10:55
  • Have you tried anything ? – Kunal Mukherjee Jul 31 '20 at 10:59
  • this is my first question and my language very bad – Agus Suhardi Jul 31 '20 at 10:59
  • 1
    It was not the language we complained about, it was the lack of attempted code – mplungjan Jul 31 '20 at 11:02

0 Answers0