SOURCE

let nums = [2, 7, 11, 15]

let target = 22

let temp = []

for(let i = 0; i < nums.length; i++) {
    let t = target - nums[i]
    if (nums.includes(t)) {
        console.log(i, nums.indexOf(t))
        break;
    }
    temp.push(t)
}
console 命令行工具 X clear

                    
>
console