function sumIndex(nums,target){ let map = new Map for(let i=0;i<nums.length;i++){ let cha = target - nums[i] if(map.has(cha)){ return [map.get(cha),i] }else{ map.set(nums[i],i) } } } let nums = [2,9,7] let target = 9 console.log(sumIndex(nums,target))