arr = [1, 2, 5, 6, 7]; for (let value of arr) { for (let val of arr) { if (val == value) { continue; } sum = value + val; if (sum != value && sum != val && arr.includes(sum)) { console.log(sum, value, val) } } }