Tengo una matriz de números y me gustaría generar todas las combinaciones posibles con 2 números como se muestra en el esperado
const numbers = [1,2,3];Esperado:
const result = [ [1,2], [1,3], [2,1], [2,3], [3,1], [3,2] ] let num = [1,2,3]; let arr = []; for(let i=0; i<num.length; i++){ for(let j=0; j<num.length; j++){ if(j === i) continue; arr.push([num[i], num[j]]); } } console.log(arr);